//#pragma GCC optimize("Ofast")
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//#pragma GCC target("avx2")
const int INF = 1e12, maxn = 3e5 + 100;
vector<pair<int, int>> g[maxn];
vector<int> used, topsort, rab;

void dfs(int v) {
    used[v] = 1;
    for (auto [u, w] : g[v]) {
        if (!used[u]) {
            dfs(u);
        }
    }
    topsort.push_back(v);
}

void dfs2(int v) {
    used[v] = 1;
    for (auto [u, w] : g[v]) {
        if (!used[u] && rab[w])
            dfs2(u);
    }
}


signed main() {
    int n, m, gr;
    cin >> n >> m >> gr;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        g[v].push_back({u, i});
    }
    rab.resize(m, 1);
    used.resize(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        if (!used[i])
            dfs(i);
    }

    reverse(topsort.begin(), topsort.end());

    for (auto v : topsort) {
        for (auto [u, w] : g[v]) {
            rab[w] = 0;
            used.assign(n + 1, 0);
            dfs2(v);
            if (used[u]) {
                rab[w] = 1;
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < m; i++) {
        if (!rab[i]) {
            cnt++;
        }
    }
    cout << cnt << '\n' << 12312;
}
