#pragma GCC optimize("O3, unroll-loops, no-stack-protector")
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#define int long long

using namespace std;

const int INF = 2e15;

int cnt = 0;

void dfs(int v, vector <multiset <int>>& g, vector <int>& used) {
	used[v] = 1;
	for (auto u : g[v]) {
		if (!used[u]) {
			dfs(u, g, used);
		}
		else if (used[u] == 1) {
			cnt++;
		}
	}
	used[v] = 2;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m, q;
	cin >> n >> m >> q;
	vector <multiset <int>> g(n);
	vector <pair<int, int>> eds;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		g[v].insert(u);
		eds.push_back({ v, u });
	}
	vector <int> used(n, 0);
	dfs(0, g, used);
	cout << cnt;
}
