#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define int ll

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, group;
    cin >> n >> m >> group;

    assert(group == 5);

    vector<int> a(n);
    int frst = n;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        v--;
        u--;

        if (u != (v + 1) % n) {
            a[u]++;
            a[v]++;
        }
        frst = min(frst, min(v, u));
    }

    if (frst == n) {
        cout << n - 1 << " " << n;
    }

    cout << "\n";
    return 0;
}