#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)((x).size()))

using ll = long long;
using ld = long double;

const ll INF = 3e18;
const ll MOD = 1e9 + 7;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> void chmax(T &a, T b) {
    if (b > a)
        a = b;
}
template <typename T> void chmin(T &a, T b) {
    if (b < a)
        a = b;
}

int bpow(int a, int e) {
    int r = 1;
    while (e) {
        if (e & 1) {
            r *= a;
            r %= MOD;
        }
        e >>= 1;
        a *= a;
        a %= MOD;
    }
    return r;
}
int inv(int a) { return bpow(a, MOD - 2); }
void solve() {
    int n, m, G;
    cin >> n >> m >> G;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
    }

    vector<bool> used(n);

    function<bool(int, pair<int, int>)> dfs = [&](auto x, const auto& y) {
        used[x] = true;

        if (x == y.second)
            return true;
        for (int u : g[x]) {
            if (used[u] || pair<int, int>{x, u} == y) continue;
            if (dfs(u, y)) return true;
        }
        return false;
    };
    int ans1 = 0;
    for (int v = 0; v < n; ++v) {
        for (int u : g[v]) {
            used.assign(n, false);
            pair<int, int> no = {v, u};
            ans1 += !dfs(v, no);
        }
    }
    cout << ans1 << '\n' << -1 << '\n';
}

signed main() {
#ifdef LOCALEGOR
    freopen("INPUT.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
    }
}
