#include <bits/stdc++.h>
using namespace std;
int vis[1010];
int main()
{
int n;
cin >> n;
int MAX = 0, MAXN = 0;
while (n--)
{
int k;
cin >> k;
while (k--)
{
int x;
cin >> x;
vis[x]++;
if (vis[x] > MAXN)
{
MAXN = vis[x];
MAX = x;
}
else if (vis[x] == MAXN)
MAX = max(MAX, x);
}
}
cout << MAX << ' ' << MAXN;
return 0;
}