#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#define int long long

using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 3e5 + 69;

vector<vector<int>> g;
vector<bool> vis;
vector<int> tps;

void make_tps(int v) {
    vis[v] = true;
    for (int u : g[v]) {
        if (!vis[u]) make_tps(u);
    }
    tps.push_back(v);
}

void reverse_g() {
    vector<vector<int>> g2(g.size());
    for (int v = 0; v < g.size(); ++v) {
        for (int u : g[v]) {
            g2[u].push_back(v);
        }
    }
    swap(g, g2);
}

vector<int> group;
void make_gr(int v, int gr) {
    vis[v] = true;
    group[v] = gr;
    for (int u : g[v]) {
        if (!vis[u]) {
            make_gr(u, gr);
        }
    }
}

vector<vector<int>> betw_gr;
vector<int> in_gr, out_gr;

void solve() {
    int n, m, testgr;
    cin >> n >> m >> testgr;
    g.resize(n);
    for (int i = 0; i < m; ++i) {
        int v, u;
        cin >> v >> u;
        --v, --u;
        g[v].push_back(u);
    }
    vis.assign(n, false);
    for (int v = 0; v < n; ++v) {
        if (!vis[v]) {
            make_tps(v);
        }
    }
    reverse_g();
    int newgr = 0;
    vis.assign(n, false);
    group.assign(n, -1);
    for (int i : tps) {
        if (!vis[i]) {
            make_gr(i, newgr++);
        }
    }
    reverse_g();
    betw_gr.resize(newgr, vector<int> (newgr));
    in_gr.resize(n);
    out_gr.resize(n);
    for (int v = 0; v < n; ++v) {
        for (int u : g[v]) {
            if (group[v] != group[u]) {
                betw_gr[group[v]][group[u]]++;
                betw_gr[group[u]][group[v]]++;
            } else {
                in_gr[u]++;
                out_gr[v]++;
            }
        }
    }
    int ans = 0;
    for (int v = 0; v < n; ++v) {
        for (int u : g[v]) {
            if (group[v] != group[u]) {
                if (betw_gr[group[v]][group[u]] > 1) {
                    ans += betw_gr[group[v]][group[u]] - 1;
                    betw_gr[group[v]][group[u]] = 1;
                }
            } else {
                if (in_gr[u] == 1 && out_gr[u]) {
                    ++ans;
                    out_gr[u] = 0;
                    in_gr[v] = 0;
                }
                if (out_gr[v] == 1 && in_gr[v]) {
                    ++ans;
                    out_gr[v] = 0;
                    in_gr[v] = 0;
                }
            }
        }
    }
    cout << ans << "\n" << 1;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
