#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;

vector<vector<int>> used;
vector<vector<int>> graph;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m, g;
    cin >> n >> m >> g;

    graph.resize(n);
    used.resize(n);
    for(int i = 0; i < n; ++i)
        used[i].resize(n);

    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        graph[u].push_back(v);
    }

    for(int i = n - 1; i >= 0; --i){
        used[i][i] = 1;
        for(auto u : graph[i]){
            for(int j = 0; j < n; ++j)
                used[i][j] = max(used[i][j], used[u][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(auto u : graph[i]){
            int flag = 0;
            for(auto z : graph[i]){
                if(z != u && used[z][u])
                    flag = 1;
            }
            ans += flag;
        }
    }
    cout << ans << endl << 1;
}
