#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <random>
#include <chrono>
#include <time.h>

//#pragma GCC optimize("O3")

#define out(x) std::cout << x << ' ';
#define oute(x) std::cout << x << '\n';
#define enter std::cout << '\n';
#define all(x) x.begin(), x.end()
using ll = long long;

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 7;
std::vector<std::vector<std::pair<ll, ll>>> g;
std::map < std::pair < ll, ll>, bool> edge;
std::vector<ll> d;
std::vector<bool> used;
ll cnt = 0;

void DFS1(ll v) {
    d[v]++;
    for (auto u : g[v]) {
        if (!used[u.second]) {
            used[u.second] = true;
            DFS1(u.first);
            break;
        }
    }
}

void DFS2(ll v) {
    d[v]++;
    for (auto u : g[v]) {
        if (!used[u.second] && d[u.first] < 2) {
            DFS2(u.first);
        }
    }
}

void s1nmeee() {
    ll n, m, G;
    std::cin >> n >> m >> G;
    g.resize(n), used.resize(m), d.resize(n);
    for (ll i = 0, x, y; i < m; i++) {
        std::cin >> x >> y;
        x--, y--;
        edge[{x, y}] = true;
        g[x].push_back({y, i});
    }
    for (ll i = 0; i < n; i++) {
        std::fill(all(used), false), std::fill(all(d), 0);
        DFS1(i), DFS2(i);
        for (ll j = 0; j < n; j++) {
            if (d[j] >= 2 && edge.find({i, j}) != edge.end()) cnt++;
        }
    }
    oute(cnt) out(1)
}

signed main() {
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
    ll TT = 1;
    //std::cin >> TT;
    while (TT--) {
        s1nmeee();
        std::cout << '\n';
    }
}