Gems (GEM)

Given range-sum constraints modulo 10 on an array of N values each in [0,100], find the lexicographically smallest valid array or report -1 if the constraints conflict.

Medium7Union-findPrefix sumGraphGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

Seonhong keeps a flower bed in the front yard. The bed is a row of NN plots numbered 1 to NN from the left, and every plot holds between 0 and 100 gems.

One day Seonhong heard a rumor that gems might be buried in the bed and decided to check with a metal detector. Given two numbers ss and ee, the detector sweeps plot ss through plot ee and reports the total number of gems buried in that range.

Seonhong swept the bed MM times and wrote down every result. Yeongmin walked by, tampered with the notes for fun, and left only the last digit of each result. Seonhong then told Yeongmin to recover the gem count of every plot from those digits alone. Help Yeongmin and find counts that do not contradict the notes.

Input

The first line has the number of plots NN and the number of sweeps MM, separated by a space. (1N1051 \le N \le 10^5, 1M1051 \le M \le 10^5)

Each of the next MM lines has sis_i, eie_i and cic_i separated by spaces. Sweep ii covered the range [si,ei][s_i, e_i], and the last digit of the total number of gems in that range was cic_i. (1sieiN1 \le s_i \le e_i \le N, 0ci90 \le c_i \le 9)

Output

Print the gem count of plot 1 through plot NN on one line, separated by spaces. Every value must be an integer between 0 and 100, and all MM sweeps must come out right.

If several arrays satisfy the sweeps, print only the lexicographically smallest one. Array aa is lexicographically smaller than array bb when ai<bia_i < b_i at the first position ii where the two arrays differ.

If the notes contradict each other and no array works, print -1 alone.