#include<bits/stdc++.h>
#pragma GCC target("avx2")
//#define int long long
#define F first
#define S second

using namespace std;

const int N = 3000+10;

vector<int> g[N], g_ob[N];

bool dfs(int v, int u, pair<int ,int> e)
{
    bool ok = bool(v == u);
    for(auto i:g_ob[v])
    {
        if(pair<int, int>{v, i} == e || pair<int, int>{i, v} == e)
            continue;
        ok |= dfs(i, u, e);
    }
    return ok;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int n, m, g;
    cin>>n>>m>>g;
    vector<pair<int, int>> v;
    for(int i = 1; i <= m; i++)
    {
        int x, y;
        cin>>x>>y;
//        g[x].push_back(y);
        g_ob[y].push_back(x);
        v.push_back({x, y});
    }
    int ans = 0;
    for(auto i:v)
        if(dfs(i.F, i.S, {i.S, i.F})) ans++;
    cout<<ans<<"\n1";

}

