Under construction

Still being built. Things may change

Binary String Toggle

Interview

Time limit2sMemory limit512 MB

Summary
Apply U range-toggle operations to an all-zero binary string and print the lexicographically largest string among all U+1 intermediate states.
Level

Medium7 of 10

Topics
Prefix sum, Greedy, Implementation
Solved
No attempts yet

Problem

There is a binary string S0S_0 of length NN whose characters are all 0. You apply UU toggle operations to it. The ii-th operation turns Si−1S_{i-1} into SiS_i, so once all UU operations are done the string is SUS_U.

The ii-th operation is given as two integers LiL_i and RiR_i. It flips every character in the range [Li,Ri][L_i, R_i]. Both ends included, every 1 inside that range becomes 0 and every 0 becomes 1.

Applying all operations gives the strings S0,S1,…,SUS_0, S_1, \dots, S_U. Write a program that finds the one that comes last in lexicographic order among these U+1U+1 strings.

Input

The first line contains NN and UU. (1≤N,U≤100,0001 \le N, U \le 100{,}000)

Each of the next UU lines contains LiL_i and RiR_i. (1≤Li≤Ri≤N1 \le L_i \le R_i \le N)

Output

On the first line, print the string that comes last in lexicographic order among the U+1U+1 strings.

Hint

For the example input, the string changes in this order.

  • S0S_0 = 0000000000
  • S1S_1 = 0000000011
  • S2S_2 = 0000011100
  • S3S_3 = 0000011111
  • S4S_4 = 1111100011
  • S5S_5 = 1100000011
  • S6S_6 = 1110000011
  • S7S_7 = 1101000011
  • S8S_8 = 1110111101
  • S9S_9 = 1111000001
  • S10S_{10} = 1111001001

Examples4

  1. Example 1

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

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

    Input
    5 1
    1 5
    
    Expected output
    11111
    
  4. Example 4

    Input
    5 3
    1 1
    2 2
    3 3
    
    Expected output
    11100