n, m = map(int, input().split())
ary = []
a = []
b = []
d = []
for i in range(m):
	s,c = map(int, input().split())
	if s == 1:
		a.append(c)
	elif s == 2:
		b.append(c)
	else:
		d.append(c)
if m == 0:
	print (-1)
	exit()
if n == 1:
	print (min(d))
	exit()
ans = 1000
if len(a) == 0:
	a.append(0)
if len(b) == 0:
	b.append(0)
if len(d) == 0:
	d.append(0)
for i in a:
	for j in b:
		for k in d:
			wk = str(i) + str(j) + str(k)
			if len(str(int(wk))) != n:
				continue
			else:
				ans = min(ans, int(wk))
if ans >= 1000:
	print (-1)
else:
	print (ans)