#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> g;
vector<vector<bool>> able;

void dfs(int v, int c) {
    able[c][v] = true;
    for (auto u : g[v]) {
        if (!able[c][u]) dfs(u, c);
    }
}

signed main() {
    int n, m, gg;
    cin >> n >> m >> gg;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
    }
    able.assign(n, vector<bool>(n));
    for (int i = 0; i < n; i++) dfs(i, i);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (auto x : g[i]) {
            bool res = false;
            for (auto y : g[i]) {
                if (x == y) continue;
                if (able[y][x]) res = true;
            }
            if (res) ans++;
        }
    }
    cout << ans;
}

