#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int MAXN = int(2010);
struct ev {
    vector<int> par;
    vector<int> siz;
    void build(int n) {
        par.resize(n + 1);
        siz.resize(n + 1);
        for (int i = 1; i <= n; i++) {
            par[i] = i;
            siz[i] = 1;
        }
    }
    int pr(int u) {
        if (u == par[u]) {
            return u;
        }
        par[u] = pr(par[u]);
        return par[u];
    }
    void upd(int u, int v) {
        u = pr(u);
        v = pr(v);
        if (u == v) {
            return;
        }
        if (siz[u] < siz[v]) {
            swap(u, v);
        }
        siz[u] += siz[v];
        par[v] = u;
    }
};
vector<int> g[MAXN];
vector<int> nw_g[MAXN];
bool f[MAXN][MAXN];
void dfs(int u, int beg) {
    f[beg][u] = true;
    for (auto to : g[u]) {
        if (f[beg][to] == false) {
            dfs(to, beg);
        }
    }
}
vector<bool> cf(MAXN, true);
/*void dfs2(int u, int beg, int v) {
    cf[u] = true;
    for (auto to : g[u]) {
        if (beg == u && to == v) {
            continue;
        }
        if (cf[to] == false) {
            dfs2(to, beg, v);
        }
    }
}*/
bool check(int u, int beg, int lst) {
    cf[u] = false;
    if (u == lst) {
        return true;
    }
    for (auto to : g[u]) {
        if (!cf[to] || (to == lst && beg == u)) {
            continue;
        }
        if (check(to, beg, lst)) {
            return true;
        }
    }
    return false;
}
void solve() {
    int n, m, gg;
    cin >> n >> m >> gg;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            f[i][j] = false;
        }
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    for (int i = 1; i <= n; i++) {
        dfs(i, i);
    }
    ev H;
    H.build(n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (f[i][j] && f[j][i]) {
                H.upd(i, j);
            }
        }
    }
    int ans = 0;
    for (int u = 1; u <= n; u++) {
        for (auto to : g[u]) {
            if (H.pr(to) == H.pr(u)) {
                continue;
            }
            for (int i = 1; i <= n; i++) {
                cf[i] = true;
            }
            if (check(u, u, to)) {
                ans++;
            }
        }
    }
    ev H2;
    H2.build(n);
    for (int u = 1; u <= n; u++) {
        for (auto to : g[u]) {
            if (H.pr(to) != H.pr(u)) {
                continue;
            }
            for (int i = 1; i <= n; i++) {
                cf[i] = true;
            }
            if (!check(u, u, to)) {
                //cout << u << ' ' << to << '\n';/
                if (H2.pr(u) != H2.pr(to)) {
                    ans++;
                }
                H2.upd(u, to);
            }
        }
    }
    /*for (int i = 1; i <= n; i++) {
        if (H2.pr(i) == i) {
            ans += H2.siz[i] - 1;
        }
    }*/
    cout << ans << '\n';
    cout << 0;
}
int32_t main() {
    /*ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
