#P1715D. 2+ doors

    ID: 889 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2-satbitmasksgraphsgreedy*1900

2+ doors

Description

The Narrator has an integer array aa of length nn, but he will only tell you the size nn and qq statements, each of them being three integers i,j,xi, j, x, which means that aiaj=xa_i \mid a_j = x, where | denotes the bitwise OR operation.

Find the lexicographically smallest array aa that satisfies all the statements.

An array aa is lexicographically smaller than an array bb of the same length if and only if the following holds:

  • in the first position where aa and bb differ, the array aa has a smaller element than the corresponding element in bb.

In the first line you are given with two integers nn and qq (1n1051 \le n \le 10^5, 0q21050 \le q \le 2 \cdot 10^5).

In the next qq lines you are given with three integers ii, jj, and xx (1i,jn1 \le i, j \le n, 0x<2300 \le x < 2^{30}) — the statements.

It is guaranteed that all qq statements hold for at least one array.

On a single line print nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai<2300 \le a_i < 2^{30}) — array aa.

Input

In the first line you are given with two integers nn and qq (1n1051 \le n \le 10^5, 0q21050 \le q \le 2 \cdot 10^5).

In the next qq lines you are given with three integers ii, jj, and xx (1i,jn1 \le i, j \le n, 0x<2300 \le x < 2^{30}) — the statements.

It is guaranteed that all qq statements hold for at least one array.

Output

On a single line print nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai<2300 \le a_i < 2^{30}) — array aa.

Sample Input 1

4 3
1 2 3
1 3 2
4 1 2

Sample Output 1

0 3 2 2

Sample Input 2

1 0

Sample Output 2

0

Sample Input 3

2 1
1 1 1073741823

Sample Output 3

1073741823 0

Note

In the first sample, these are all the arrays satisfying the statements:

  • [0,3,2,2][0, 3, 2, 2],
  • [2,1,0,0][2, 1, 0, 0],
  • [2,1,0,2][2, 1, 0, 2],
  • [2,1,2,0][2, 1, 2, 0],
  • [2,1,2,2][2, 1, 2, 2],
  • [2,3,0,0][2, 3, 0, 0],
  • [2,3,0,2][2, 3, 0, 2],
  • [2,3,2,0][2, 3, 2, 0],
  • [2,3,2,2][2, 3, 2, 2].