#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> gr;
vector<int> vst;
vector<int> tp;
void dfs(int v) {
    vst[v] = 1;
    for (auto x : gr[v]) {
        if (!vst[x]) dfs(x);
    }
    tp.push_back(v);
}
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m, g; cin >> n >> m >> g;
    gr.resize(n); vst.resize(n);
    vector<int> deg(n);
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >>v;
        u--; v--;
        gr[u].push_back(v);
        deg[v]++;
    }
    for (int i = 0; i < n; i++) {
        if (!vst[i]) dfs(i);
    }
    reverse(tp.begin(), tp.end());
    int cnt = 0;
    for (auto x : tp) {
        if (deg[x]) cnt++;
    }
    cout << cnt << '\n';
    cout << -1 << '\n';
    return 0;
}
