Tram

No attempts yetTime limit2sMemory limit512 MB

Statement

Byteman collects photos of old vehicles. One day, looking out of his window, he saw a rare old tram stopped at the stop right in front of his house, but it left before he could pick up his camera, so he missed the shot. He wants to be ready next time.

Byteman lives in Bytetown, which has nn junctions numbered from 11 to nn, with one tram stop at each junction. Trams always arrive at whole minutes. Instead of checking the stop every single minute, Byteman decides to set his camera to photograph the stop every TT minutes, taking the moment the tram first appears as minute 00.

He wants the largest period TT such that, no matter which route the tram takes, every moment it returns to his stop is a multiple of TT. That way the camera never misses the tram.

Generalizing, for each junction jj define the value TjT_j as follows. Suppose the tram appears at junction jj at minute 00 and then travels along the tracks. TjT_j is the largest integer such that, over every route the tram may take, every later moment at which the tram is again at junction jj is a multiple of TjT_j.

The tram keeps moving as long as it can. It stops only when it reaches a junction with no outgoing track (a dead end); otherwise it may run forever. The time spent waiting at a stop is negligible.

If junction jj has no outgoing track, or if a tram leaving junction jj can never return to jj, then Tj=1T_j = -1.

For every junction jj from 11 to nn, compute TjT_j.

Input

The first line contains two integers nn and mm (1n,m100,0001 \le n, m \le 100{,}000), separated by a single space: the number of junctions and the number of tracks. Junctions are numbered from 11 to nn.

Each of the next mm lines contains three integers aia_i, bib_i, cic_i (1ai,bin1 \le a_i, b_i \le n, 1ci10,0001 \le c_i \le 10{,}000), separated by single spaces. Each such track is one-way and lets a tram travel from junction aia_i to junction bib_i in cic_i minutes.

Both directions between a pair of junctions may exist, and ai=bia_i = b_i is allowed (a loop at a single junction). For any given direction there is at most one track between a pair of junctions.

The time a tram spends waiting at a stop is negligible, and the tram travels as long as it can (until it reaches a dead end, or forever if it never does).

Output

Print nn integers, each on its own line. The jj-th line must contain TjT_j.

Note

In the example above, a tram leaving junction 22 can return after, for instance, 88, 1010, or 1212 minutes. So, for the camera not to miss any appearance of the tram, it must be set to take a photo every two minutes, giving T2=2T_2 = 2.