This page is still under construction.

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

Alternating Current

Time limit3sMemory limit1024 MB

Summary
Each of M circular arcs must get a direction (clockwise or counter-clockwise) so that every segment lies in at least one arc of each direction, or report impossible.
Level

Medium7 of 10

Topics
Graph, BFS, Implementation, Greedy
Solved
No attempts yet

Problem

Fredrik has a model railway consisting of NN segments connected in a circle. The segments are numbered 1,2,…,N1, 2, \dots, N in clockwise order. Electricity is supplied through MM curved wires running along the circle, and every segment is covered by at least one wire.

Fredrik wants to install a switch on every segment. The switches need alternating current. In Fredrik's view, alternating current means current flowing in both directions. Each wire carries current in one direction only, clockwise or counter-clockwise, and Fredrik can choose the direction of every wire. The directions must be chosen so that every segment is covered by at least one wire with clockwise current and at least one wire with counter-clockwise current.

Find such a choice of directions if one exists.

The figure above shows a solution for the first sample. The curved arrows outside the railway are the wires, and each arrow direction is Fredrik's choice of current direction. Reversing every arrow gives another valid solution.

This idea makes sense because the railway is Swedish, and in Sweden every switch (in Swedish växlar) uses alternating current (in Swedish växelström).

Input

The first line contains two integers NN and MM, the number of segments and the number of wires.

Each of the next MM lines contains two integers aa and bb with 1≤a,b≤N1 \le a, b \le N. The wire covers segments a,a+1,…,ba, a+1, \dots, b. If bb is smaller than aa, the interval wraps around the circle and covers segments a,…,N,1,…,ba, \dots, N, 1, \dots, b. If a=ba = b, the wire covers only that single segment.

Output

Output a single line with MM characters, each 00 or 1. The iith character must be 0 if the current in the iith input wire flows clockwise, and 1 if it flows counter-clockwise. If several solutions exist, output any of them.

If no valid solution exists, output impossible.

Examples4

  1. Example 1

    Input
    10 5
    1 5
    6 7
    5 1
    7 2
    2 4
    
    Expected output
    00101
    
  2. Example 2

    Input
    10 5
    1 4
    2 5
    4 7
    6 10
    8 1
    
    Expected output
    impossible
    
  3. Example 3

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

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