시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 256 MB42232354.762%

문제

Let $n$ be a positive integer. Find the number of integers $1 \le M \le n$ for which there exists an array of integers $a[1..n]$ that satisfies the following conditions: $$ a[x_i] + 1 \equiv a[y_i] \pmod{M} , \quad 1 \le i \le q . $$

입력

The first line contains two integers, $n$ and $q$: the array size and the number of conditions ($1\le n, q \le 10^6$).

Each of the next $q$ lines contains two integers, $x_i$ and $y_i$: the indices describing the corresponding condition ($1 \le x_i, y_i \le n$).

출력

On the first line, print an integer $t$: the number of possible values of $M$. On the second line, print the $t$ possible values of $M$ in increasing order.

예제 입력 1

3 3
1 2
2 3
3 1

예제 출력 1

2
1 3

예제 입력 2

5 5
1 2
2 3
3 4
4 5
1 5

예제 출력 2

2
1 3

예제 입력 3

5 5
1 2
2 3
3 1
4 5
5 4

예제 출력 3

1
1

예제 입력 4

5 1
1 2

예제 출력 4

5
1 2 3 4 5