#include using namespace std; using pii = pair; using ll = long long; const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f; int n, m, w[N]; int f[N], d[N], c, k; void solve() { scanf("%d%d%d", &n, &m, &k); for (int i = 1, a, b; i < m + 1; i++) { scanf("%d%d", &a, &b); f[a] = 1, d[b]++; } priority_queue, greater > q; ll res = 0; for (int i = 1; i < n + 1; i++) if (f[i]) res += max(0, k - d[i]), c++; else q.push(max(0, k - d[i])); while (c < k + 1) { res += q.top(); q.pop(); c++; } printf("%lld\n", res); } int main() { int T = 1; // scanf("%d", &T); while (T--) solve(); return 0; }