
int main()
{
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++)
    {
        int s, t;
        scanf("%d %d", &s, &t);
        graph1[s].push_back(t);
        graph2[t].push_back(s);
    }

    int count = 0;

    for (int i = 1; i <= N; i++)