//代码3
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int ans[10005];
char str[100001];
int main()
{
    int n;
    cin >> n;
    int i, k = 0;
    getchar();
    for (i = 0; i < n; i++)
    {
        gets(str);
        char *p;
        p = strtok(str, " ");
        ans[k++] = atoi(p);
        while (p)
        {
            p = strtok(NULL, " ");
            if (p)
                ans[k++] = atoi(p);
        }
    }
    sort(ans, ans + k);
    int ans1, ans2;
    for (i = 0; i < k - 1; i++)
    {
        if (ans[i + 1] - ans[i] == 2)
        {
            ans1 = ans[i] + 1;
        }
        if (ans[i + 1] == ans[i])
            ans2 = ans[i];
    }
    cout << ans1 << " " << ans2;
}