Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$.

There are three values about each exam:  $s_i$ — the day, when questions for the $i$-th exam will be published,  $d_i$ — the day of the $i$-th exam ($s_i < d_i$),  $c_i$ — number of days Petya needs to prepare for the $i$-th exam. For the $i$-th exam Petya should prepare in days between $s_i$ and $d_i-1$, inclusive. 

There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $i$-th exam in day $j$, then $s_i \le j < d_i$.

It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days.

Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible.


-----Input-----

The first line contains two integers $n$ and $m$ $(2 \le n \le 100, 1 \le m \le n)$ — the number of days and the number of exams.

Each of the following $m$ lines contains three integers $s_i$, $d_i$, $c_i$ $(1 \le s_i < d_i \le n, 1 \le c_i \le n)$ — the day, when questions for the $i$-th exam will be given, the day of the $i$-th exam, number of days Petya needs to prepare for the $i$-th exam. 

Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given.


-----Output-----

If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $n$ integers, where the $j$-th number is:  $(m + 1)$, if the $j$-th day is a day of some exam (recall that in each day no more than one exam is conducted),  zero, if in the $j$-th day Petya will have a rest,  $i$ ($1 \le i \le m$), if Petya will prepare for the $i$-th exam in the day $j$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).

Assume that the exams are numbered in order of appearing in the input, starting from $1$.

If there are multiple schedules, print any of them.


-----Examples-----
Input
5 2
1 3 1
1 5 1

Output
1 2 3 0 3 

Input
3 2
1 3 1
1 2 1

Output
-1

Input
10 3
4 7 2
1 10 3
8 9 1

Output
2 2 2 1 1 0 4 3 4 4 



-----Note-----

In the first example Petya can, for example, prepare for exam $1$ in the first day, prepare for exam $2$ in the second day, pass exam $1$ in the third day, relax in the fourth day, and pass exam $2$ in the fifth day. So, he can prepare and pass all exams.

In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.

Difficulty: MEDIUM_HARD

Solutions:
def sol():
	(n, m) = list(map(int, input().split()))
	arr = []
	for d in range(m):
		preArr = list(map(int, input().split()))
		preArr[0] -= 1
		preArr[1] -= 1
		arr.append(preArr)
	out = [m] * n
	for i in range(n):
		ind = 999999999999999
		exm = False
		exmDate = 9999999999999
		for g in range(m):
			if arr[g][1] == i:
				exm = True
				break
			if arr[g][1] > i and arr[g][2] > 0 and (arr[g][0] <= i):
				if arr[g][1] < exmDate:
					exmDate = arr[g][1]
					ind = g
		if exm:
			out[i] = m + 1
		elif exmDate == 9999999999999:
			out[i] = 0
		else:
			out[i] = ind + 1
			arr[ind][2] -= 1
	for i in range(m):
		if arr[i][2] != 0:
			break
	else:
		print(*out)
		return 0
	print(-1)
sol()


import sys
(n, m) = map(int, input().split())
sdc = [tuple(map(int, input().split())) for _ in range(m)]
isdc = list(enumerate(sdc))
isdc.sort(key=lambda _: _[1][1])
a = [0 for _ in range(n + 1)]
for (i, sdc) in isdc:
	(s, d, c) = sdc
	a[d] = m + 1
for (i, sdc) in isdc:
	(s, d, c) = sdc
	for k in range(s, d):
		if a[k] == 0 and c > 0:
			a[k] = i + 1
			c -= 1
	if c > 0:
		print(-1)
		sys.exit(0)
print(*a[1:])


def read():
	return list(map(int, input().strip().split(' ')))
(n, m) = read()
arr = []
for i in range(m):
	(s, d, c) = read()
	arr.append([s, d, c, i])
arr.sort(key=lambda arr: arr[1])
ans = [0] * (n + 1)
for elem in arr:
	(s, d, c, ind) = elem
	for i in range(s, d):
		if ans[i] == 0:
			ans[i] = ind + 1
			c -= 1
			if c == 0:
				break
	if c > 0:
		ans = [0, -1]
		break
	ans[d] = m + 1
print(*ans[1:])


(n, m) = map(int, input().split())
ans = [0] * n
f = 0
li = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	li.append((b, a, c, i + 1))
li.sort()
for i in range(m):
	(b, a, c, k) = li[i]
	ans[b - 1] = m + 1
	j = a - 1
	cnt = 0
	while j < b and cnt < c:
		if ans[j] == 0:
			ans[j] = k
			cnt += 1
		j += 1
	if cnt != c:
		f = 1
if f:
	print(-1)
else:
	print(*ans)


f = lambda : map(int, input().split())
(n, m) = f()
t = []
p = [0] * (n + 1)
for i in range(1, m + 1):
	(s, d, c) = f()
	if p[d]:
		exit(print(-1))
	p[d] = m + 1
	t.append((i, s, d, c))
t.sort(key=lambda q: q[2])
for (i, s, d, c) in t:
	while c:
		if not p[s]:
			p[s] = i
			c -= 1
		if s == d:
			exit(print(-1))
		s += 1
print(*p[1:])


from sys import stdin
input = stdin.buffer.readline
(n, m) = map(int, input().split())
exams = []
for i in range(m):
	(s, d, c) = map(int, input().split())
	exams.append((i, s, d, c))
exams.sort(key=lambda x: x[2])
dp = [-1] + [0] * n
for i in exams:
	dp[i[2]] = m + 1
flag = False
for exam in exams:
	s = exam[1]
	d = exam[2]
	c = exam[3]
	while s < d and c > 0:
		if dp[s] == 0:
			dp[s] = exam[0] + 1
			c = c - 1
		s = s + 1
	if c > 0:
		flag = True
		break
if flag:
	print(-1)
else:
	print(*dp[1:])


(n, m) = map(int, input().split())
L = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	L.append([b, a, c, i])
L.sort()
M = [-1 for i in range(n + 1)]
for i in range(m):
	M[L[i][0]] = m + 1
for i in range(1, n + 1):
	if M[i] == -1:
		f = False
		for j in range(m):
			if L[j][1] <= i and L[j][2] > 0 and (i < L[j][0]):
				M[i] = L[j][3] + 1
				L[j][2] -= 1
				f = True
				break
		if not f:
			M[i] = 0
f = True
for j in range(m):
	if L[j][2] > 0:
		f = False
if f:
	print(*M[1:])
else:
	print(-1)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	(n, m) = mi()
	exams = []
	ans = [0] * n
	for i in range(m):
		tmp = li()
		tmp += [i + 1]
		ans[tmp[1] - 1] = m + 1
		exams.append(tmp)
	exams = sorted(exams, key=lambda x: x[1])
	flag = 0
	for i in exams:
		data = i
		if data[1] - data[0] < data[2]:
			flag = 1
			break
		need = data[2]
		for j in range(data[0], data[1]):
			if ans[j - 1] == 0 and need > 0:
				ans[j - 1] = data[3]
				need -= 1
		if need != 0:
			flag = 1
	if flag:
		print(-1)
	else:
		print(*ans)
main()


(n, m) = map(int, input().split())
array = [0] * (n + 1)
lst = []
for x in range(m):
	(s, d, c) = map(int, input().split())
	lst.append((d, s, c, x + 1))
lst.sort()
i = 0
flag = True
for (d, s, c, p) in lst:
	x = s
	while c > 0 and x < d:
		if array[x] == 0:
			array[x] = p
			c -= 1
		x += 1
	if c != 0:
		flag = False
		break
	else:
		array[d] = m + 1
if flag:
	print(*array[1:])
else:
	print(-1)


(n, m) = map(int, input().split())
arr = []
for i in range(1, m + 1):
	(s, d, c) = map(int, input().split())
	arr.append((d, s, c, i))
arr.sort()
ans = [0] * (n + 1)
for (d, s, c, i) in arr:
	j = s
	ef = False
	for k in range(c):
		while j < d and ans[j] != 0:
			j += 1
		if j >= d:
			ef = True
			break
		ans[j] = i
	if ef:
		print(-1)
		break
	if ans[d] == 0:
		ans[d] = m + 1
	else:
		print(-1)
		break
else:
	print(*ans[1:])


def ke(i):
	return b[i]
(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
e = []
ans = [0] * n
for i in range(m):
	(a[i], b[i], c[i]) = map(int, input().split())
	ans[b[i] - 1] = m + 1
	e.append(i)
e.sort(key=ke)
for i in range(m):
	k = 0
	for j in range(a[e[i]] - 1, b[e[i]] - 1):
		if ans[j] == 0:
			ans[j] = e[i] + 1
			k += 1
		if k == c[e[i]]:
			break
	if k != c[e[i]]:
		print(-1)
		exit(0)
for i in ans:
	print(i, end=' ')


from collections import namedtuple
Exam = namedtuple('Exam', 'id s d c')

def get_exam(day, exams, prepared):
	result = None
	for exam in exams:
		if exam.s <= day and prepared[exam.id] < exam.c and (result is None or exam.d < result.d):
			result = exam
	return result
(n, m) = list(map(int, input().split()))
exams = []
prepared = [0] * (m + 1)
schedule = [0] * (n + 1)
for i in range(m):
	(s, d, c) = list(map(int, input().split()))
	exams.append(Exam(i + 1, s, d, c))
	schedule[d] = -1
for day in range(1, n + 1):
	if schedule[day] == -1:
		print(-1)
		return
	if schedule[day] == m + 1:
		continue
	exam = get_exam(day, exams, prepared)
	if exam is None:
		continue
	prepared[exam.id] += 1
	schedule[day] = exam.id
	if prepared[exam.id] == exam.c:
		schedule[exam.d] = m + 1
print(' '.join(map(str, schedule[1:])))


import heapq
(n, m) = [int(s) for s in input().split()]
(q0, q1) = ([], [])
ans = [0] * n
for i in range(m):
	(si, di, ci) = [int(s) for s in input().split()]
	si -= 1
	di -= 1
	ans[di] = m + 1
	heapq.heappush(q0, (si, di, ci, i))
for currday in range(n):
	while len(q0) and q0[0][0] <= currday:
		(si, di, ci, i) = heapq.heappop(q0)
		heapq.heappush(q1, (di, si, ci, i))
	if len(q1) and ans[currday] == 0:
		if currday > q1[0][0]:
			break
		ans[currday] = q1[0][3] + 1
		if q1[0][2] == 1:
			heapq.heappop(q1)
		else:
			q1[0] = (q1[0][0], q1[0][1], q1[0][2] - 1, q1[0][3])
if len(q1) == 0 and len(q0) == 0:
	print(*ans)
else:
	print(-1)


l = input().split()
n = int(l[0])
m = int(l[1])
l = []
hashipapers = dict()
curr = [0 for i in range(m)]
for i in range(m):
	lo = input().split()
	s = int(lo[0])
	d = int(lo[1])
	c = int(lo[2])
	hashipapers[d - 1] = (i, c)
	l.append((d - 1, s - 1, c, i))
l.sort()
lfi = []
poss = 1
for i in range(n):
	if i in hashipapers:
		lfi.append(m + 1)
		if curr[hashipapers[i][0]] < hashipapers[i][1]:
			poss = 0
			break
		continue
	found = 0
	for j in l:
		if j[0] > i and i >= j[1] and (curr[j[3]] < j[2]):
			found = 1
			curr[j[3]] += 1
			lfi.append(j[3] + 1)
			break
	if found == 0:
		lfi.append(0)
if poss == 0:
	print(-1)
else:
	for i in lfi:
		print(i, end=' ')


import bisect
(n, m) = list(map(int, input().split()))
a = []
b = []
for i in range(m):
	(s, d, c) = list(map(int, input().split()))
	if c > d - s + 1:
		print(-1)
		quit()
	l = bisect.bisect_left(b, d)
	a.insert(l, [s, d, c, i + 1])
	b.insert(l, d)
ds = list(('0' for i in range(n)))
for i in range(m):
	(s, d, c, mi) = a[i]
	c0 = 0
	for j in range(s, d):
		if ds[j - 1] == '0':
			ds[j - 1] = str(mi)
			c0 += 1
		if c0 >= c:
			break
	if c0 < c:
		print(-1)
		quit()
	ds[d - 1] = str(m + 1)
print(' '.join(ds))


import heapq
(n, m) = map(int, input().split())
is_exam = [False]
is_exam.pop()
is_exam.append(next(map(int, (0, 1))))
is_exam.extend([False] * n)
starting_exams = [[(0, 0, 0)]]
starting_exams.pop()
starting_exams.append(next(map(int, (0, 1))))
starting_exams.extend(([] for _ in range(n)))
for i in range(1, m + 1):
	(si, di, ci) = map(int, input().split())
	starting_exams[si].append((di, ci, i))
	is_exam[di] = True
next_exams = [(0, 0, 0)]
res = [0]
next_exams.pop()
res.pop()
for j in range(1, n + 1):
	for di_cii_ne_tra in starting_exams[j]:
		heapq.heappush(next_exams, di_cii_ne_tra)
	if next_exams:
		(di, ci, i) = heapq.heappop(next_exams)
		if di == j:
			print('-1')
			exit()
		elif is_exam[j]:
			res.append(m + 1)
		else:
			res.append(i)
			ci -= 1
		if ci:
			heapq.heappush(next_exams, (di, ci, i))
	elif is_exam[j]:
		res.append(m + 1)
	else:
		res.append(0)
print(*res)


import sys
from collections import *
import math
input = sys.stdin.readline
(n, m) = [int(x) for x in input().split()]
arr = [0] * n
h = Counter()
c = Counter()
for i in range(m):
	arr[i] = tuple([int(x) for x in input().split()])
	h[arr[i][1]] = arr[i][2]
	c[arr[i][1]] = 1
arr1 = []
cnt = [0] * n
p = 0
for i in range(n):
	if c[i + 1] == 1 and cnt[i] < h[i + 1]:
		p = -1
		break
	if c[i + 1] == 1 and cnt[i] == h[i + 1]:
		arr1.append(m + 1)
		del c[i + 1]
		continue
	res = 101
	for j in range(m):
		if i >= arr[j][0] - 1 and arr[j][1] < res and (arr[j][1] > i + 1) and (cnt[arr[j][1] - 1] < h[arr[j][1]]):
			res = arr[j][1]
			index = j
	if res == 101:
		arr1.append(0)
	else:
		arr1.append(index + 1)
		cnt[arr[index][1] - 1] += 1
if p == 0:
	for i in arr1:
		print(i, end=' ')
else:
	print(-1)


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]

def solve():
	(n, m) = zzz()
	deed = [0] * n
	exams = []
	for i in range(m):
		(s, d, c) = zzz()
		s -= 1
		d -= 1
		if deed[d]:
			return [-1]
		deed[d] = m + 1
		exams.append((d, s, c, i + 1))
	exams = sorted(exams)
	for (d, s, c, idx) in exams:
		for i in range(s, d):
			if deed[i] == 0:
				deed[i] = idx
				c -= 1
				if c == 0:
					break
		if c:
			return [-1]
	return deed
print(*solve())


(n, m) = list(map(int, input().split()))
(s, d, c) = (list(), list(), list())
for i in range(m):
	(si, di, ci) = list(map(int, input().split()))
	s.append(si - 1)
	d.append(di - 1)
	c.append(ci)
(s, d, c, num) = zip(*sorted(list(zip(s, d, c, list(range(m)))), key=lambda x: x[1]))
exam_num = [-1 for _ in range(n)]
for i in range(m):
	exam_num[d[i]] = i
cnt = [0 for _ in range(m)]

def run():
	res = []
	for i in range(n):
		j = exam_num[i]
		if j != -1:
			if cnt[j] < c[j]:
				print(-1)
				return
			res.append(m + 1)
		else:
			next_exam = -1
			for j in range(m):
				if s[j] <= i and d[j] > i and (cnt[j] < c[j]):
					next_exam = j
					break
			if next_exam == -1:
				res.append(0)
			else:
				res.append(num[j] + 1)
				cnt[j] += 1
	print(' '.join([str(x) for x in res]))
run()


import io
import os
from collections import defaultdict
from sys import stdin, stdout

def main():
	(n, m) = map(int, input().split())
	exams = []
	for _ in range(m):
		(a, b, c) = map(int, input().split())
		exams.append((a, b, c))
	exam_days = {}
	for (i, exam) in enumerate(exams):
		exam_days[exam[1]] = i + 1
	prepared = [0] * m
	res = []
	for day in range(1, n + 1):
		if day in exam_days:
			res.append(m + 1)
		else:
			cand = None
			for i in range(m):
				(start, exam_day, to_prepare) = exams[i]
				if start <= day <= exam_day and to_prepare > prepared[i]:
					if cand is None or exam_day < exams[cand][1]:
						cand = i
			if cand is None:
				res.append(0)
			else:
				res.append(cand + 1)
				prepared[cand] += 1
	if all((prepared[i] == exams[i][2] for i in range(m))):
		print(*res)
	else:
		print(-1)
main()


from sys import stdin

def main():
	(n, m) = map(int, stdin.readline().split())
	s = [0] * (m + 1)
	d = [0] * (m + 1)
	c = [0] * (m + 1)
	check = [-1] * (n + 1)
	for i in range(1, m + 1):
		(s[i], d[i], c[i]) = map(int, stdin.readline().split())
		check[d[i]] = i
	ans = [0] * (n + 1)
	ok = True
	done = [False] * (m + 1)
	for i in range(1, n + 1):
		if not ok:
			break
		if check[i] != -1:
			if c[check[i]] == 0:
				ans[i] = m + 1
				done[check[i]] = True
			else:
				ok = False
				break
		else:
			candi = []
			for j in range(1, m + 1):
				if s[j] <= i and c[j] > 0 and (not done[j]):
					candi.append(j)
			if not candi:
				ans[i] = 0
			else:
				candi.sort(key=lambda x: d[x])
				select = candi[0]
				ans[i] = select
				c[select] -= 1
	if ok:
		print(*ans[1:])
	else:
		print(-1)
main()


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k) = map(int, input().split())
l = []
se = set()
for i in range(k):
	(a, b, c) = map(int, input().split())
	l.append((a, b, c, i))
	se.add(b)
l.sort()
stack = []
t = 0
ans = [0] * n
for i in range(n):
	if t < k:
		while l[t][0] == i + 1:
			stack.append([-l[t][1], l[t][2], l[t][-1]])
			t += 1
			if t == k:
				break
	if len(stack) == 0:
		continue
	stack.sort()
	for j in range(len(stack)):
		if -stack[j][0] == i + 1:
			print(-1)
			sys.exit(0)
	if i + 1 in se:
		continue
	stack[-1][1] -= 1
	ans[i] = stack[-1][2] + 1
	if stack[-1][1] == 0:
		stack.pop()
for i in range(k):
	ans[l[i][1] - 1] = k + 1
print(*ans)


(n, m) = map(int, input().split())
c = []
for i in range(m):
	c.append([int(x) for x in input().split()])
	c[i].append(i + 1)
a = [0] * n
c.sort(key=lambda x: x[1])
for i in c:
	a[i[1] - 1] = m + 1
	x = i[2]
	for j in range(i[0] - 1, i[1]):
		if x == 0:
			break
		if a[j] == 0:
			a[j] = i[3]
			x -= 1
	if x > 0:
		print(-1)
		exit()
print(*a)


I = lambda : list(map(int, input().split()))
(n, m) = I()
dates = [0 for i in range(n + 1)]
data = []
for i in range(m):
	d = I() + [i + 1]
	if dates[d[1]]:
		print(-1)
		return
	dates[d[1]] = m + 1
	data.append(d)
data.sort(key=lambda x: x[1])
for (s, d, c, idx) in data:
	x = 0
	for i in range(s, d):
		if x == c:
			break
		if not dates[i]:
			dates[i] = idx
			x += 1
	if x != c:
		print(-1)
		return
print(*dates[1:])


(n, m) = [int(x) for x in input().split()]
res = [0] * n
quant = []
for i in range(m):
	(s, d, c) = [int(x) for x in input().split()]
	res[d - 1] = m + 1
	quant.append((d - 1, s - 1, c, i + 1))
quant.sort()
for q in quant:
	(d, s, c, i) = (q[0], q[1], q[2], q[3])
	while c:
		if res[s] == 0:
			res[s] = i
			c -= 1
		if s == d:
			exit(print('-1'))
		s += 1
print(*res)


(n, m) = map(int, input().split())
prep = []
days = [-1] * n
release = []
for i in range(m):
	(s_, d_, c_) = map(int, input().split())
	release.append(s_)
	days[d_ - 1] = i
	prep.append(c_)
rel_on_day = {}
for (i, r) in enumerate(release):
	if r - 1 in rel_on_day:
		rel_on_day[r - 1].append(i)
	else:
		rel_on_day[r - 1] = [i]
ans = []
waiting = set()
exam_q = []
for d in days:
	if d != -1:
		exam_q.append(d)
for i in range(n):
	if i in rel_on_day:
		waiting = waiting | set(rel_on_day[i])
	if days[i] != -1:
		if prep[days[i]] == 0:
			ans.append(m + 1)
			waiting.remove(days[i])
		else:
			print(-1)
			exit(0)
	else:
		chosen = None
		for ex in exam_q:
			if prep[ex] > 0 and ex in waiting:
				chosen = ex
				break
		if not chosen is None:
			prep[ex] -= 1
			ans.append(ex + 1)
		else:
			ans.append(0)
print(' '.join(list(map(str, ans))))


def update(si, ei, di, lst, i, ee):
	cur = si
	cnt = 0
	while cnt < di and cur < ei:
		if lst[cur] == 0:
			lst[cur] = i + 1
			cnt += 1
		cur += 1
	lst[ei] = ee + 1
	return True if cnt >= di else False
(n, e) = map(int, input().split())
lst = [0] * n
fl = True
query = []
for i in range(e):
	(si, ei, di) = map(int, input().split())
	query.append((si, ei, di, i))
query.sort(key=lambda e: e[1])
for el in query:
	(si, ei, di, i) = el
	si -= 1
	ei -= 1
	if ei - si < di:
		fl = False
		break
	elif not update(si, ei, di, lst, i, e):
		fl = False
		break
if not fl:
	print(-1)
else:
	print(' '.join(map(str, lst)))


(n, m) = map(int, input().split())
ans = [0] * n
exams = []
for i in range(m):
	(s, d, c) = map(int, input().split())
	s -= 1
	d -= 1
	if ans[d]:
		print('-1')
		exit(0)
	ans[d] = m + 1
	exams.append((d, s, c, i + 1))
for (d, s, c, id) in sorted(exams):
	for i in range(s, d):
		if ans[i] == 0:
			ans[i] = id
			c -= 1
			if c == 0:
				break
	else:
		print('-1')
		exit(0)
print(*ans)


rd = lambda : map(int, input().split())
(n, m) = rd()
a = sorted(([*rd()] + [i + 1] for i in range(m)), key=lambda x: x[1])
r = [0] * n
for x in a:
	r[x[1] - 1] = m + 1
	for i in range(x[0] - 1, x[1] - 1):
		if not r[i]:
			r[i] = x[3]
			x[2] -= 1
			if not x[2]:
				break
	if x[2]:
		print(-1)
		exit()
print(*r)


import sys
from heapq import heappush, heappop

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, M) = MAP()
prep = [[] for i in range(N)]
need = [0] * M
exam = {}
for i in range(M):
	(s, d, c) = MAP()
	s -= 1
	d -= 1
	need[i] = c
	prep[s].append((d, i))
	exam[d] = i
que = []
ans = [0] * N
for day in range(N):
	for (d, i) in prep[day]:
		heappush(que, (d, i))
	if day in exam:
		i = exam[day]
		if need[i] > 0:
			print(-1)
			exit()
		ans[day] = M + 1
	elif que:
		(d, i) = heappop(que)
		need[i] -= 1
		if need[i] > 0:
			heappush(que, (d, i))
		ans[day] = i + 1
print(*ans)


(a, b) = map(int, input().split())
m = [0] * a
m1 = []
for i in range(b):
	m1.append(list(map(int, input().split())))
	m[m1[-1][1] - 1] = b + 1
	m1[-1].append(i + 1)
m1.sort(key=lambda x: x[1])
for i in m1:
	c = i[2]
	for j in range(i[0] - 1, i[1]):
		if m[j] == 0:
			m[j] = i[3]
			c -= 1
		if c == 0:
			break
		if j + 1 == len(m):
			break
	if c != 0:
		m1.sort()
		m = [0] * a
		for i in m1:
			m[i[1] - 1] = b + 1
		for i in m1:
			c = i[2]
			for j in range(i[0] - 1, i[1]):
				if m[j] == 0:
					m[j] = i[3]
					c -= 1
				if c == 0:
					break
				if j + 1 == len(m):
					break
			if c != 0:
				m = False
				break
		break
if m == False:
	print(-1)
else:
	print(*m)


from queue import PriorityQueue
possible = True
(n, m) = map(int, input().split())
publish = []
on_desk = PriorityQueue()
num_on_desk = 0
todo = {}
result = []
for j in range(1, m + 1):
	(s, d, c) = map(int, input().split())
	publish += [(s, d, c, j)]
publish.sort()
j = 0
for i in range(1, n + 1):
	while j < m and publish[j][0] <= i:
		on_desk.put(publish[j][1])
		num_on_desk += 1
		todo[publish[j][1]] = (publish[j][2], publish[j][3])
		j += 1
	if num_on_desk > 0:
		deadline = on_desk.get()
		on_desk.put(deadline)
	elif i not in todo:
		result += [0]
		continue
		if deadline < i:
			possible = False
			break
	if i in todo:
		if todo[i][0] == 0:
			result += [m + 1]
		else:
			possible = False
			break
	elif todo[deadline][0] > 0:
		(rem, ind) = todo[deadline]
		rem -= 1
		todo[deadline] = (rem, ind)
		result += [ind]
		if rem == 0:
			tmp = on_desk.get()
			num_on_desk -= 1
if possible:
	assert len(result) == n
	print(' '.join(map(str, result)))
else:
	print(-1)


R = lambda : map(int, input().split())
(n, m) = R()
a = []
for i in range(m):
	(s, d, c) = R()
	a.append([d, s, c, i + 1])
a.sort()
r = [0] * (n + 1)
for i in range(m):
	r[a[i][0]] = m + 1
for i in range(m):
	for j in range(a[i][1], a[i][0]):
		if a[i][2] == 0:
			break
		elif r[j] == 0:
			r[j] = a[i][3]
			a[i][2] -= 1
	if a[i][2]:
		print(-1)
		exit()
print(*r[1:])


def solve(n, m, ss, dd, cc):
	date = [-1] * (n + 1)
	for (j, d) in enumerate(dd):
		date[d] = j
	start = [[] for _ in range(n + 1)]
	for (j, d) in enumerate(ss):
		start[d].append(j)
	preps = []
	for i in range(1, n + 1):
		if start[i]:
			preps += start[i]
		u = date[i]
		if u >= 0:
			j = u
			if cc[j] > 0:
				return -1
			date[i] = m + 1
		elif not preps:
			date[i] = 0
		else:
			min_d = min((dd[j] for j in preps))
			for j in preps:
				if dd[j] == min_d:
					break
			date[i] = j + 1
			cc[j] -= 1
			if cc[j] == 0:
				preps.remove(j)
	return date[1:]

def main():
	(n, m) = [int(_) for _ in input().split()]
	s = []
	d = []
	c = []
	for i in range(m):
		(s_, d_, c_) = [int(_) for _ in input().split()]
		s.append(s_)
		d.append(d_)
		c.append(c_)
	plan = solve(n, m, s, d, c)
	if isinstance(plan, list):
		print(' '.join(map(str, plan)))
	else:
		print(-1)
main()


a = input().split(' ')
a = [int(e) for e in a]
isdc = []
for i in range(a[1]):
	l = input().split(' ')
	l = [int(e) for e in l]
	isdc.append([i + 1, l[0] - 1, l[1] - 1, l[2]])
l = [0] * a[0]
for e in isdc:
	l[e[2]] = len(isdc) + 1
isdc = sorted(isdc, key=lambda one: one[2])
for exam in isdc:
	day = exam[1]
	while day < exam[2]:
		if exam[3] == 0:
			break
		if l[day] == 0:
			l[day] = exam[0]
			exam[3] -= 1
		day += 1
	if exam[3] != 0:
		print(-1)
		exit()
for e in l:
	print(e, end=' ')


import sys
(n, m) = [int(c) for c in input().split()]
s = []
d = []
c = []
studying = []
for _ in range(m):
	(x, y, z) = [int(w) for w in input().split()]
	s.append(x)
	d.append(y)
	c.append(z)
plan = []
for i in range(1, n + 1):
	if i in s:
		indices = [k for (k, x) in enumerate(s) if x == i]
		for idx in indices:
			studying.append((d[idx], idx))
		studying.sort()
	if i in d:
		idx = d.index(i)
		if (i, idx) in studying:
			print(-1)
			sys.exit()
		else:
			plan.append(m + 1)
	else:
		if not studying:
			plan.append(0)
			continue
		idx = studying[0][1]
		plan.append(idx + 1)
		c[idx] -= 1
		if c[idx] == 0:
			studying = studying[1:]
for i in plan:
	print(i, end=' ')
print()


(n, m) = map(int, input().split())
exams = []
examday = set()
for i in range(m):
	(s, d, c) = map(int, input().split())
	exams.append((i, s, d, c))
	examday.add(d)
prep = [0] * m
s_exams = exams[:]
s_exams.sort(key=lambda x: x[2])
ans = []
for day in range(1, n + 1):
	if day in examday:
		ans.append(m + 1)
		continue
	for (i, s, d, c) in s_exams:
		if day < s or day > d:
			continue
		if prep[i] == c:
			continue
		prep[i] += 1
		ans.append(i + 1)
		break
	else:
		ans.append(0)
for i in range(m):
	if prep[i] < exams[i][3]:
		print(-1)
		exit(0)
print(*ans)


(n, m) = map(int, input().split())
exams = []
for i in range(m):
	e = list(map(int, input().split()))
	e.append(0)
	e.append(i + 1)
	exams.append(e)
exams.sort()
(now, have, f, ans, c) = (0, [], True, [], 0)
for i in range(1, n + 1):
	while now < m and exams[now][0] == i:
		have.append(exams[now][1:])
		now += 1
		have.sort()
	if c < len(have) and have[c][0] == i:
		if have[c][1] == have[c][2]:
			ans.append(m + 1)
			c += 1
		else:
			f = False
			break
	else:
		j = 0
		while j < len(have) and have[j][1] == have[j][2]:
			j += 1
		if j == len(have):
			ans.append(0)
		else:
			ans.append(have[j][3])
			have[j][2] += 1
if f:
	for i in range(n):
		print(ans[i], end=' ')
else:
	print(-1)


(n, m) = map(int, input().split())
x = [0] * n
t = []
for i in range(m):
	(s, d, c) = map(int, input().split())
	x[d - 1] = m + 1
	t.append((d - 1, s - 1, c, i + 1))
t.sort()
for (d, s, c, i) in t:
	for k in range(s, d):
		if not x[k]:
			x[k] = i
			c -= 1
			if c == 0:
				break
	if c > 0:
		print(-1)
		break
else:
	print(' '.join(map(str, x)))


(n, m) = map(int, input().split())
SDC = []
ans = [0] * n
D = {}
for i in range(m):
	(s, d, c) = map(int, input().split())
	SDC.append((s, d, c))
	ans[d - 1] = m + 1
	D[d - 1] = i
C = [0] * m
for i in range(n):
	if ans[i] == 0:
		e = 10 ** 18
		k = -1
		for j in range(m):
			(s, d, c) = SDC[j]
			if d <= e and s <= i + 1 and (i + 1 <= d) and (C[j] < c):
				e = d
				k = j
		if k != -1:
			ans[i] = k + 1
			C[k] += 1
	else:
		j = D[i]
		(s, d, c) = SDC[j]
		if C[j] < c:
			print(-1)
			exit()
print(*ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
a = list()
for i in range(m):
	(s, c, d) = map(int, input().split())
	a.append((c, s, d, i + 1))
a.sort()
b = [0] * n
tot = 0
for i in range(m):
	c = a[i][0]
	s = a[i][1]
	d = a[i][2]
	nm = a[i][3]
	free = 0
	for j in range(s - 1, c - 1):
		if b[j] == 0:
			free += 1
	if free >= d and b[c - 1] == 0:
		tot += 1
		b[c - 1] = -1
		for j in range(s - 1, c - 1):
			if b[j] == 0:
				b[j] = nm
				d -= 1
			if d <= 0:
				break
	if tot >= m:
		break
if tot != m:
	print(-1)
else:
	for i in range(n):
		if b[i] == -1:
			b[i] = m + 1
	print(*b)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, m) = iia()
arr = []
for i in range(m):
	arr.append(iia() + [i + 1])
arr.sort(key=lambda x: [x[1], x[0], x[2], x[3]])
i = j = 0
res = [0] * n
for i in arr:
	(s, d, c, ind) = i
	while c:
		if not res[s - 1]:
			res[s - 1] = ind
			c -= 1
		if s == d:
			exit(print(-1))
		s += 1
	res[d - 1] = m + 1
print(*res)


def main():
	(n, m) = map(int, input().split())
	a = []
	ans = [0] * n
	for i in range(m):
		(x, y, z) = map(int, input().split())
		ans[y - 1] = m + 1
		a.append([y - 1, x - 1, z, i + 1])
	a.sort()
	for i in range(m):
		count = 0
		for j in range(a[i][1], a[i][0]):
			if count == a[i][2]:
				break
			if ans[j] == 0:
				ans[j] = a[i][3]
				count += 1
		if count < a[i][2]:
			print(-1)
			return
	for i in range(n):
		print(ans[i], end=' ')
main()


(n, m) = [int(i) for i in input().split()]
s = [0] * m
d = [0] * m
c = [0] * m
for i in range(m):
	(s[i], d[i], c[i]) = [int(j) - 1 for j in input().split()]
	c[i] += 1
	if d[i] - s[i] < c[i]:
		print(-1)
		quit()
ans = [0] * n
for i in d:
	ans[i] = m + 1
exam = []
for i in range(n):
	exam.append([])
	for j in range(m):
		if s[j] <= i < d[j]:
			exam[i].append(j)
for i in range(n):
	if ans[i] == 0:
		day_min = n + 1
		for j in exam[i]:
			if d[j] < day_min and c[j] > 0:
				day_min = d[j]
				exam_min = j
		if day_min != n + 1:
			ans[i] = exam_min + 1
			c[exam_min] -= 1
	elif c[d.index(i)] != 0:
		print(-1)
		quit()
for i in range(n):
	if i != n - 1:
		print(ans[i], end=' ')
	else:
		print(ans[i])


import heapq
(n, m) = map(int, input().split())
ans = [0] * n
ary = []
dp = [[0] * n for i in range(n)]
tmp = 0
while tmp < m:
	(s, d, c) = map(int, input().split())
	s -= 1
	d -= 1
	ans[d] = m + 1
	ary.append((s, d, c + 1, tmp))
	dp[s][d] = c
	tmp += 1
d = 2
while d < n:
	l = 0
	while l + d < n:
		r = l + d
		dp[l][r] += dp[l + 1][r] + dp[l][r - 1] - dp[l + 1][r - 1]
		if dp[l][r] > d:
			print(-1)
			quit(0)
		l += 1
	d += 1
l = 0
pos = 0
sary = sorted(ary)
que = []
while l < n:
	while pos < m and sary[pos][0] == l:
		heapq.heappush(que, [sary[pos][1], sary[pos][2], sary[pos][3]])
		pos += 1
	if ans[l] > 0:
		l += 1
		continue
	if que.__len__() == 0:
		l += 1
		continue
	head = heapq.heappop(que)
	if head[1] + l - 1 > head[0]:
		print(-1)
		quit(0)
	head[1] -= 1
	ans[l] = head[2] + 1
	if head[1] > 1:
		heapq.heappush(que, head)
	l += 1
if que.__len__() > 0 or pos < m:
	print(-1)
else:
	print(*ans)


import sys
from heapq import heappush, heappop
(d, b) = map(int, input().split())
examdays = {}
exams = {}
outday = [list() for i in range(d)]
left = {}
ans = [-1] * d
for i in range(b):
	(prep, exam, dur) = map(int, input().split())
	outday[prep - 1].append(i)
	left[i] = dur
	examdays[i] = exam - 1
	exams[exam - 1] = i
curlist = []
for j in range(d):
	for p1 in outday[j]:
		heappush(curlist, (examdays[p1], left[p1], p1))
	if j in exams:
		if left[exams[j]] > 0:
			print('-1')
			sys.exit()
		else:
			ans[j] = b + 1
	elif len(curlist) > 0:
		cur = heappop(curlist)
		ans[j] = cur[2] + 1
		left[cur[2]] -= 1
		if cur[1] != 1:
			heappush(curlist, (cur[0], cur[1] - 1, cur[2]))
	else:
		ans[j] = 0
print(' '.join(map(str, ans)))


import heapq
(n, m) = map(int, input().split())
sdc = [tuple(map(int, (input() + ' ' + str(i)).split())) for i in range(m)]
heapq.heapify(sdc)
p = [False] * m
hq = []
hqd = []
ans = [0] * n
for i in range(1, n + 1):
	while sdc and sdc[0][0] == i:
		(s, d, c, x) = heapq.heappop(sdc)
		heapq.heappush(hq, (d, c, x))
		heapq.heappush(hqd, (d, x))
	if hqd and hqd[0][0] == i:
		(d, x) = heapq.heappop(hqd)
		if p[x]:
			ans[i - 1] = m + 1
		else:
			print(-1)
			exit(0)
	elif hq:
		(x, y, z) = heapq.heappop(hq)
		y -= 1
		ans[i - 1] = z + 1
		if y == 0:
			p[z] = True
		else:
			heapq.heappush(hq, (x, y, z))
print(*ans)


from heapq import heapify, heappop, heappush
(n, m) = map(int, input().split())
ans = [0] * (n + 1)
lis = []
aa = 0
for i in range(m):
	(s, d, c) = map(int, input().split())
	ans[d] = m + 1
	lis.append([s, d, c, i + 1])
	aa += c
lis.sort()
heap = []
heapify(heap)
i = 1
while i <= n:
	while len(lis) > 0 and lis[0][0] == i:
		heappush(heap, [lis[0][1], lis[0][0], lis[0][2], lis[0][3]])
		del lis[0]
	if len(heap) > 0:
		a = heappop(heap)
		if a[0] < i:
			heap.append([1, 1, 1, 1])
			break
		if ans[i] == 0:
			ans[i] = a[3]
			a[2] -= 1
		if a[2] != 0:
			heappush(heap, a)
	i += 1
if len(heap) != 0:
	print(-1)
	exit()
print(*ans[1:])


(n, m) = map(int, input().split())
res = []
ans = [0] * (n + 1)
ind = [0] * (n + 1)
for i in range(m):
	(s, d, c) = map(int, input().split())
	ind[d] = i + 1
	res.append([d, s, c])
res.sort()
flag = 0
for i in range(m):
	[d, s, c] = res[i]
	j = s
	ex = ind[d]
	ans[d] = m + 1
	while c > 0 and j < d:
		if ans[j] == 0:
			ans[j] = ex
			c -= 1
		j += 1
	if c != 0:
		print(-1)
		flag = 1
		break
if flag == 0:
	print(*ans[1:])


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, m) = rint()
s = [0 for i in range(m)]
d = [0 for i in range(m)]
c = [0 for i in range(m)]
for i in range(m):
	(s[i], d[i], c[i]) = rint()
s_in_day = [set() for i in range(n + 1)]
for i in range(m):
	day = s[i]
	s_in_day[day].add(i)
d_in_day = [-1 for i in range(n + 1)]
for i in range(m):
	day = d[i]
	d_in_day[day] = i
di_sorted = [0 for i in range(m)]
di_sorted.sort(key=lambda x: d[i])
ans = [0 for i in range(n + 1)]
candi_exam = set()
for day in range(1, n + 1):
	for exam in s_in_day[day]:
		candi_exam.add(exam)
	if d_in_day[day] != -1:
		exam = d_in_day[day]
		if c[exam] != 0:
			print(-1)
			exit()
		ans[day] = m + 1
		if exam in candi_exam:
			candi_exam.remove(exam)
		continue
	if len(candi_exam) == 0:
		ans[day] = 0
		continue
	min_d_day = 101
	busy_exam = 0
	for exam in candi_exam:
		if d[exam] < min_d_day:
			busy_exam = exam
			min_d_day = d[exam]
	ans[day] = busy_exam + 1
	c[busy_exam] -= 1
	if c[busy_exam] == 0:
		candi_exam.remove(busy_exam)
for i in range(m):
	if c[i] != 0:
		print(-1)
		exit()
print(*ans[1:])


(n, m) = map(int, input().split())
ls = [0 for i in range(n)]
prep = []
order = []
for i in range(m):
	(s, d, c) = map(int, input().split())
	ls[d - 1] = m + 1
	prep.append([s, d, c])
	order.append([d, i])
order.sort()
for i in range(n):
	if ls[i] == 0:
		for j in range(m):
			if prep[order[j][1]][0] - 1 <= i < prep[order[j][1]][1] - 1:
				if prep[order[j][1]][2]:
					ls[i] = order[j][1] + 1
					prep[order[j][1]][2] -= 1
					break
flag = True
for i in range(m):
	if prep[i][2] != 0:
		flag = False
if flag:
	print(*ls)
else:
	print(-1)


(n, m) = map(int, input().split())
x = []
ans = [0] * n
for i in range(m):
	(s, d, c) = map(int, input().split())
	x.append([d - 1, s - 1, c, i + 1])
	ans[d - 1] = m + 1
x.sort()
for (d, s, c, i) in x:
	cnt = 0
	while cnt < c:
		if s == d:
			print(-1)
			exit()
		if ans[s] == 0:
			ans[s] = i
			cnt += 1
		s += 1
print(*ans)


(n, m) = map(int, input().split())
l = list()
out = [0] * n
for i in range(m):
	(s1, d1, c1) = map(int, input().split())
	l.append((s1, d1, c1, i))
l.sort(key=lambda x: x[1])
can = True
for j in l:
	out[j[1] - 1] = m + 1
for i in l:
	c = i[2]
	for t in range(i[0], i[1]):
		if out[t - 1] == 0 and c > 0:
			out[t - 1] = i[3] + 1
			c -= 1
		if c == 0:
			break
	if c != 0:
		print(-1)
		can = False
		break
if can is True:
	print(' '.join(map(str, out)))


import sys
from collections import Counter
from queue import PriorityQueue
read = lambda : map(int, sys.stdin.buffer.readline().split())
(n, m) = read()
v = [tuple(read()) + tuple([i + 1]) for i in range(m)]
v.sort(key=lambda x: (x[1], x[0], x[2]))
s = Counter()
for x in v:
	s[x[1]] += 1
pre = 0
q = PriorityQueue()
ans = True
res = {}
for t in v:
	if t[1] in s and s[t[1]] > 1:
		ans = False
		break
	res[t[1]] = m + 1
	for i in range(pre + 1, t[1]):
		if i not in s:
			q.put(i)
	pre = t[1]
	q1 = []
	tmp = t[2]
	while not q.empty():
		x = q.get()
		if x in res:
			continue
		if x < t[0]:
			q1.append(x)
		else:
			tmp -= 1
			res[x] = t[3]
		if tmp == 0:
			break
	for x in q1:
		q.put(x)
	if tmp:
		ans = False
		break
if not ans:
	print(-1)
else:
	for i in range(1, n + 1):
		if i in res:
			print(res[i], end=' ')
		else:
			print(0, end=' ')


from heapq import heappop, heappush, heapify
(n, m) = map(int, input().split())
arr = [[] for i in range(n + 1)]
ans = [-1 for i in range(n + 1)]
for i in range(m):
	(strt, end, req) = map(int, input().split())
	arr[strt].append([end, req, i + 1])
	ans[end] = end
he = []
(req, indx, end) = (0, 0, 0)
flag = 0
for i in range(1, n + 1):
	for j in arr[i]:
		heappush(he, j)
	if not he:
		if ans[i] == -1:
			ans[i] = 0
		else:
			ans[i] = m + 1
	if he:
		(end, req, indx) = heappop(he)
		if ans[i] == -1:
			ans[i] = indx
			req -= 1
		elif end <= ans[i]:
			flag = 1
			break
		else:
			ans[i] = m + 1
		if req > 0:
			heappush(he, [end, req, indx])
if flag == 1:
	print(-1)
else:
	for i in range(1, n + 1):
		if ans[i] != -1:
			print(ans[i], end=' ')
	print()


from sys import stdin, stdout
import math
(N, M) = [int(x) for x in stdin.readline().split()]
s = [0] * M
d = [0] * M
c = [0] * M
ans = [0] * N
for i in range(M):
	arr = [int(x) for x in stdin.readline().split()]
	s[i] = arr[0]
	d[i] = arr[1]
	ans[d[i] - 1] = M + 1
	c[i] = arr[2]
exams = {}
for i in range(N):
	exams[i + 1] = []
for j in range(M):
	L = s[j]
	R = d[j]
	for k in range(L, R):
		exams[k].append((j + 1, R))
for i in range(N):
	exams[i + 1].sort(key=lambda x: x[1])
for i in range(N):
	if ans[i] == M + 1:
		continue
	find = 0
	for j in range(len(exams[i + 1])):
		p = exams[i + 1][j]
		test_id = p[0] - 1
		if c[test_id] > 0:
			find = 1
			ans[i] = test_id + 1
			c[test_id] -= 1
			break
	if find == 0:
		ans[i] = 0
if sum(c) == 0:
	print(*ans)
else:
	print(-1)


from bisect import *
(n, m) = map(int, input().split())
r = [0] * n
q = []
for i in range(m):
	(s, d, c) = map(int, input().split())
	r[d - 1] = m + 1
	q.append([d - 1, s - 1, c, i + 1])
q.sort()
for i1 in q:
	(d, s, c, i) = (i1[0], i1[1], i1[2], i1[3])
	while c:
		if r[s] == 0:
			r[s] = i
			c -= 1
		if s == d:
			print(-1)
			exit(0)
		s += 1
print(*r)


def solve():
	(n, m) = map(int, input().split())
	deed = [0] * n
	exams = []
	for i in range(m):
		(s, d, c) = map(int, input().split())
		s -= 1
		d -= 1
		if deed[d]:
			return [-1]
		deed[d] = m + 1
		exams.append((d, s, c, i + 1))
	for (d, s, c, idx) in sorted(exams):
		for i in range(s, d):
			if deed[i] == 0:
				deed[i] = idx
				c -= 1
				if c == 0:
					break
		else:
			return [-1]
	return deed
print(*solve())


[n, m] = [int(x) for x in input().split()]
I = 0
S = 1
D = 2
C = 3
exses = [[0, 0, 0, 0]]
pops = [0] * (n + 1)
i = 1
while i <= m:
	[s, d, c] = [int(x) for x in input().split()]
	exses.append([i, s, d, c])
	pops[d] = i
	i += 1
i = 1
result = [0] * (n + 1)
fail = False
while i <= n:
	if pops[i] != 0 and exses[pops[i]][C] == 0:
		result[i] = m + 1
	elif pops[i] != 0 and exses[pops[i]][C] > 0:
		fail = True
		break
	else:
		ex = None
		min = n + 1
		for e in exses:
			if e[D] > i and e[S] <= i and (e[D] < min) and (e[C] > 0):
				min = e[D]
				ex = e
		if ex == None:
			result[i] = 0
		else:
			result[i] = ex[I]
			ex[C] -= 1
	i += 1
if fail:
	print(-1)
else:
	for x in result[1:]:
		print(x, end=' ')


(n, m) = map(int, input().split())
s = [0] * (m + 1)
d = [0] * (m + 1)
c = [0] * (m + 1)
ans = [0] * (n + 1)
for i in range(1, m + 1):
	(s[i], d[i], c[i]) = map(int, input().split())
	ans[d[i]] = m + 1
for i in range(1, n + 1):
	if ans[i] != 0:
		continue
	(mn, pos) = (1000, 0)
	for j in range(1, m + 1):
		if c[j] > 0 and s[j] <= i and (i < d[j]) and (d[j] < mn):
			mn = d[j]
			pos = j
	if mn < 1000:
		ans[i] = pos
		c[pos] -= 1
for i in range(1, m + 1):
	if c[i] > 0:
		print(-1)
		exit(0)
print(*ans[1:])


from collections import defaultdict

class Exam:

	def __init__(self, id, questions_day, date, preparation_days):
		self.id = id
		self.questions_day = questions_day
		self.date = date
		self.preparation_days = preparation_days

	def __repr__(self):
		return 'Exam: {{id: {3}, questions day: {0}, date: {1}, preparation days: {2}}}'.format(self.questions_day, self.date, self.preparation_days, self.id)

def read_numbers():
	return [int(n) for n in input().strip().split(' ')]

def main():
	(session_days, exam_count) = read_numbers()
	exams = []
	schedule = defaultdict(int)
	for idx in range(exam_count):
		exam_raw = read_numbers()
		exam = Exam(idx + 1, *exam_raw)
		schedule[exam.date] = exam_count + 1
		exams.append(exam)
	preparations = defaultdict(int)
	exams.sort(key=lambda ex: ex.date)
	for day in range(1, session_days + 1):
		if day in schedule:
			ex = list(filter(lambda ex: ex.date == day, exams))[0]
			if ex.preparation_days > preparations[ex.id]:
				print(-1)
				return
			continue
		urgent_exam = None
		for exam in exams:
			if exam.date > day and preparations[exam.id] < exam.preparation_days and (exam.questions_day <= day):
				urgent_exam = exam
				break
		if urgent_exam:
			preparations[urgent_exam.id] += 1
			schedule[day] = urgent_exam.id
		else:
			schedule[day] = 0
	for day in range(1, session_days + 1):
		print(schedule[day], end=' ')
	print()
main()


class exam1:

	def __init__(self, ind, ee):
		self.ind = ind
		self.ee = ee

class exam:

	def __init__(self, qq, ee, pp, ind):
		self.qq = qq
		self.ee = ee
		self.pp = pp
		self.ind = ind
yoar = list(map(int, input().split()))
n = yoar[0]
m = yoar[1]
ans = []
examar = []
paperar = []
paperdayar = []
for i in range(n):
	ans.append(0)
	paperdayar.append([])
for i in range(m):
	yoar = list(map(int, input().split()))
	qq = yoar[0] - 1
	ee = yoar[1] - 1
	pp = yoar[2]
	examar.append(exam(qq, ee, pp, i))
	ans[ee] = examar[-1]
	paperdayar[qq].append(exam1(i, ee))
flag = 0
for i in range(n):
	if paperdayar[i] != []:
		for j in paperdayar[i]:
			paperar.append(j)
	paperar.sort(key=lambda exam1: exam1.ee)
	if type(ans[i]) == exam:
		if examar[ans[i].ind].pp > 0:
			print(-1)
			flag = 1
			break
	elif paperar == []:
		ans[i] = 0
	else:
		ans[i] = paperar[0].ind + 1
		examar[paperar[0].ind].pp -= 1
		if examar[paperar[0].ind].pp == 0:
			del paperar[0]
if flag == 0:
	for i in range(n):
		if type(ans[i]) == exam:
			print(m + 1, end=' ')
		else:
			print(ans[i], end=' ')
	print()