from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
#import math
#import time
import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True


n,m=LI()
d=[inf]*(n+1)
dp=[inf]*(n+1)
s_dp=[inf]*(n+1)
dp[1]=0
s_dp[1]=0
path=[[] for _ in range(n+1)]
for i in range(m):
    l,r,c=LI()
    #l,r=l-1,r-1
    path[l].append((l,r,c))
    show([0]*l+[c]*(r-l)+[0]*(n-r-1))
    for i in range(l,r):
        d[i]=min(d[i],c)

q_g=[[] for _ in range(1+n)]
q_s=[[] for _ in range(1+n)]
for x in range(1,n):
    # 新規パスのスタック
    for p in path[x]:
        q_s[x].append(p)
        l,r,c=p
        q_g[r].append(p)
    
    # 終点になるパスの処理
    while q_g[x+1]:
        l,r,c=q_g[x+1].pop()
        dp[x+1]=min(dp[x+1],dp[l]+c)

show()
show(dp)
show(d)
for i in groupby(d):
    show(i[0],end=' ')

    