Under construction

Still being built. Things may change

Password Decryption

Time limit2sMemory limit512 MB

Summary
Given M range-XOR constraints on an unknown array of N numbers, find any array satisfying all constraints or report that none exists.
Level

Medium7 of 10

Topics
Union-find, Graph, Bit manipulation, Prefix sum
Solved
No attempts yet

Problem

Junki invented a new rule for encrypting a sequence of NN (1≤N≤2⋅1051 \le N \le 2 \cdot 10^5) numbers. Junki's encryption consists of MM (1≤M≤2⋅1051 \le M \le 2 \cdot 10^5) clues.

The ii-th clue consists of three values Li,Ri,XORiL_i, R_i, XOR_i (1≤Li≤Ri≤N1 \le L_i \le R_i \le N, 0≤XORi≤1090 \le XOR_i \le 10^9), which means that the bitwise XOR of the LiL_i-th through RiR_i-th numbers in Junki's sequence equals XORiXOR_i.

Seungwon heard Junki's encryption rule and tried to find a way to recover NN numbers satisfying the given rule, but failed in the end. Help Seungwon by writing a program that, given Junki's encryption rule, outputs NN numbers satisfying the given rule.

Input

The first line gives N,MN, M separated by a space (1≤N,M≤2⋅1051 \le N, M \le 2 \cdot 10^5).

From the second line, MM lines follow, each giving Li,Ri,XORiL_i, R_i, XOR_i (1≤Li≤Ri≤N1 \le L_i \le R_i \le N, 0≤XORi≤1090 \le XOR_i \le 10^9) separated by spaces. This means that the bitwise XOR of the LiL_i-th through RiR_i-th numbers in the array equals XORiXOR_i.

Output

Print NN numbers separated by spaces that satisfy all MM given rules. The numbers making up the resulting array must be between 00 and 2⋅1092 \cdot 10^9 inclusive. If multiple sequences satisfy the conditions, output any one of them. If no sequence satisfies all conditions, print −1-1.

Examples3

  1. Example 1

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

    Input
    6 6
    1 3 0
    2 3 1
    2 6 0
    3 5 0
    4 6 0
    2 5 1
    
    Expected output
    -1
    
  3. Example 3

    Input
    7 4
    1 3 5
    2 3 3
    4 6 2
    3 7 1
    
    Expected output
    6 6 5 5 0 7 6