#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define int ll

const int MOD = 1e9+7;

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

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

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

    assert(group == 5);

    vector<int> a(n);
    int frst = n;
    int lst = -1;
    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));
            lst = max(lst, max(v, u));
        }
    }

    if (frst == n) {
        cout << n - 1 << " " << n;
    } else {
        int ans = n - lst + frst;
        int ans0 = n - lst + frst - 1;
        for (int i = frst; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (a[j] != 0) {
                    ans = (ans * (j - i)) % MOD;
                    ans0 += j - i - 1;
                    i = j - 1;
                    break;
                }
            }
        }
        cout << ans0 << " " << ans;
    }

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