Under construction

Still being built. Things may change

Plain Constructive Problem

Interview

Time limit1sMemory limit1024 MB

Summary
Given N and M intervals, build a sequence of length N with the largest K such that every interval contains all values 1 to K.
Level

Easy3 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

Given an integer NN and MM integer pairs (L_1,R_1),(L_2,R_2),⋯(L_M,R_M)(L\_1, R\_1), (L\_2, R\_2), \cdots (L\_M, R\_M), find the sequence XX that maximizes KK under the following conditions.

  • XX consists of NN positive integers, each at most KK.
  • For every pair (L_i,R_i)(L\_i, R\_i), the subarray X_L_i,X_L_i+1,⋯ ,X_R_i−1,X_R_iX\_{L\_i}, X\_{L\_i+1}, \cdots, X\_{R\_i-1}, X\_{R\_i} must contain every positive integer at most KK.

Input

The first line contains two integers NN and MM.

The next MM lines each contain two integers L_iL\_i and R_iR\_i. (1≤i≤N)(1 \le i \le N)

Output

For a sequence XX that satisfies the conditions, print the NN integers X_1,X_2,⋯ ,X_NX\_1, X\_2, \cdots, X\_N.

If multiple answers exist, print any of them.

Constraints

  • 3≤N≤10003 \leq N \leq 1000
  • 1≤M≤10001 \leq M \leq 1000
  • 1≤L_i≤R_i≤N1 \leq L\_i \leq R\_i \leq N

Examples2

  1. Example 1

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

    Input
    3 2
    1 2
    2 3
    
    Expected output
    1 2 1