This page is still under construction.

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

Group Division

Interview

Time limit1sMemory limit1024 MB

Summary
Assign each chair to group 1 or 2 so that every prefix is balanced within 1 and paired chairs match, choosing the lexicographically smallest sequence.
Level

Medium6 of 10

Topics
Greedy, Union-find, Implementation, Math
Solved
No attempts yet

Problem

Math teacher Maria plans to divide her students into two groups during the next lesson. So she now faces a common problem: how do you divide students into two groups in a sensible way? There are nn students in the class, and the classroom has nn chairs, numbered from 11 to nn. When a student arrives in the classroom, they always sit on the free chair that is furthest to the left. So if a total of kk people show up on a given day, they always sit on chairs 1,2,…,k1, 2, \dots, k.

To divide the students into two groups, Maria has a strategy she wants to use. Before the lesson starts, she chooses a sequence ss of nn ones and twos. When the lesson has started, she goes to each student and makes the student sitting on chair ii end up in group sis_i. For the group division to be sensible, two requirements must hold for ss:

  1. Maria does not know how many students will come, but no matter how many show up, the difference in size between the two groups must be at most 11.
  2. There are mm pairs of chairs that have the same color. If students sit on such a pair of chairs, they must end up in the same group.

Your task is, given n,mn, m and the mm pairs of chairs, to find the sequence ss that comes first in alphabetical order and satisfies the requirements above. If there is no valid ss, your program must print −1-1.

By alphabetical order we mean that two sequences are compared by first checking the first character, if it is the same checking the second, and so on. For example, the sequence 1122 comes before 1211, but after 1112.

Input

The first line contains two integers 1≤n≤1051 \le n \le 10^5, the number of chairs in the classroom, and 0≤m≤n/20 \le m \le n/2, the number of chair pairs with the same color. Then follow mm lines, each consisting of two integers, the pairs of chairs that have the same color (1-indexed). Each chair has the same color as at most one other chair.

Output

Print a sequence of nn ones or twos (without spaces), or −1-1 if there is no valid solution.

Examples3

  1. Example 1

    Input
    7 3
    2 3
    4 5
    6 7
    
    Expected output
    1221122
    
  2. Example 2

    Input
    8 3
    1 3
    2 5
    4 7
    
    Expected output
    12122121
    
  3. Example 3

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