#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back


using namespace std;

vector <int> g[2020], og[2020];
bool us[2020][3];
int ans = 0;

void dfs(int v, int r) {
    if(r == 1 && us[v][1])
        return;
    if(r == 1)
        us[v][1] = 1;
    if(r > 1 && us[v][2])
        return;
    if(r > 1)
        us[v][2] = 1;
    for(auto to : g[v]) {
        dfs(to, r + 1);
    }
}

void solve() {
    int n, m, G;
    cin >> n >> m >> G;
    for(int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        og[v].pb(u);
    }
//    for(int i = 1; i <= n; i++) {
//        w[i] = og[i].size();
//    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            us[j][1] = 0, us[j][2] = 0;
        }
        dfs(i, 0);
        for(int j = 1; j <= n; j++) {
            if(us[j][1] && us[j][2])
                ans++;
        }
    }
    cout << ans << "\n";
    cout << "1\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
