# Code

/*
_______                       ________                        _______
/ _____ \                     / ______ \                      / _____ \
/ /     \_\  _     __     _   / /      \ \   _     __     _   / /     \_\
| |          | |   |  |   | | | |        | | | |   |  |   | | | |
| |          | |   |  |   | | | |     __ | | | |   |  |   | | | |
| |       __ \  \  |  |  /  / | |     \ \| | \  \  |  |  /  / | |       __
\ \_____/ /  \  \/ /\ \/  /   \ \_____\  /   \  \/ /\ \/  /   \ \_____/ /
\_______/    \___/  \___/     \______/\__\   \___/  \___/     \_______/
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 6e5;

int cnt = 1, n, m, top, dfx, tot, num;

int head[N + 50], id[N + 50], idask[N + 50], idpre[N + 50], lst[N + 50], scc[N + 50], dfn[N + 50], st[N + 50], low[N + 50];

vector<int> crimer;

struct Node
{
int next, to;
} edge[N * 8 + 50];

{
//	cout << endl;
//	cout << u << " " << v << endl;
return;
}

{
Addedge(v ^ 1, u ^ 1);
return;
}

void Tarjan(int x)
{
dfn[x] = low[x] = ++dfx; st[++top] = x;
for (int i = head[x]; i; i = edge[i].next)
{
int v = edge[i].to;
if (!dfn[v])
{
Tarjan(v);
low[x] = min(low[x], low[v]);
}
else if (!scc[v]) low[x] = min(low[x], dfn[v]);
}
if (low[x] == dfn[x])
{
tot++;
while (st[top + 1] != x) scc[st[top--]] = tot;
}
return;
}

inline char nc(){
#define SIZE 1000000+3
static char buf[SIZE],*p1 = buf+SIZE,*p2 = buf+SIZE;
if(p1 == p2){
if(p1 == p2) return -1;
}
return *p1++;
#undef SIZE
}

template <typename T>
x = 0;int flag = 0;char ch = nc();
while(!isdigit(ch)){
if(ch == '-') flag = 1;
ch = nc();
}
while(isdigit(ch)){
x = (x<<1) + (x<<3) + (ch^'0');
ch = nc();
}
if(flag) x = -x;
}

int main()
{
for (int i = 1; i <= n; i++) cnt += 2, id[i] = cnt;
for (int i = 1; i <= m; i++) cnt += 2, idask[i] = cnt, cnt += 2, idpre[i] = cnt;
for (int i = 1, x, y, t; i <= m; i++)
{
lst[x] = idpre[i];