#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#define all(v) v.begin(), v.end()
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<long long, long long> pii;

const ll SZ = 2000;

vector<ll> g[SZ];
vector<ll> g2[SZ];
ll used[SZ];

ll cnt = 0;

void dfs(ll v) {
	used[v] = 1;
	for (auto u : g[v]) {
		if (!used[u]) {
			dfs(u);
		}
		else {
			cnt++;
		}
	}
}

void solve() {
	ll n, m, h, v, u;
	cin >> n >> m >> h;
	vector<pii> edges;
	for (ll i = 0; i < m; i++) {
		cin >> v >> u;
		g[--v].push_back(--u);
		edges.push_back({ v, u });
	}
	for (ll i = 0; i < n; i++) {
		if (!used[i]) {
			dfs(i);
		}
	}
	cout << cnt << '\n';
}

int main() {
	ll t = 1;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	cin >> t;
#else
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#endif
	while (t--) solve();
}
