This page is still under construction.

Parts of this page are still being built. What you see may change.

Restricted Arrays

Time limit4sMemory limit256 MB

Summary
Count the moduli M up to n for which some integer array satisfies a[x]+1 = a[y] (mod M) for every given pair, and list them.
Level

Hard8 of 10

Topics
Graph, Union-find, Number theory, Math
Solved
No attempts yet

Problem

Let nn be a positive integer. Find the number of integers MM with 1≤M≤n1 \le M \le n for which there exists an array of integers a[1..n]a[1..n] satisfying the following conditions: a[xi]+1≡a[yi](modM),1≤i≤qa[x_i] + 1 \equiv a[y_i] \pmod{M}, \quad 1 \le i \le q

Input

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

Each of the next qq lines contains two integers, xix_i and yiy_i: the indices describing the corresponding condition (1≤xi,yi≤n1 \le x_i, y_i \le n).

Output

On the first line, print an integer tt: the number of possible values of MM. On the second line, print the tt possible values of MM in increasing order.

Examples4

  1. Example 1

    Input
    3 3
    1 2
    2 3
    3 1
    
    Expected output
    2
    1 3
    
  2. Example 2

    Input
    5 5
    1 2
    2 3
    3 4
    4 5
    1 5
    
    Expected output
    2
    1 3
    
  3. Example 3

    Input
    5 5
    1 2
    2 3
    3 1
    4 5
    5 4
    
    Expected output
    1
    1
    
  4. Example 4

    Input
    5 1
    1 2
    
    Expected output
    5
    1 2 3 4 5