from scipy.sparse.csgraph import shortest_path
import numpy as np

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
 

n, m = map(int,readline().split())

inf = 10**15

g = np.full((n+1, n+1), inf)

for i in range(m):
    l, r, c = map(int,readline().split())
    g[l-1:r, l-1:r] = np.minimum(g[l-1:r, l-1:r], c)
    
print(g)