N, M = map(int, input().split())
_i = [input().split() for _ in range(M)]

x, h = "", 0
for _ in range(1, N+1, 1):
	y, z = 0, 0
	for idx, _j in enumerate(_i):
		if str(_) == _j[0]:
			if y:
				if z != _j[1]:
					h += 1
					break
				else:
					y += 1
					continue
			else:
				x += str(_j[1])
				z = _j[1]
				y += 1
				continue
				
		elif idx != M - 1:
			continue
		elif not y:
			x += "0"
			

if not M:
	h = 1
if h:
	x = -1

x = int(x)
if not x:
	print(-1)
else:
	print(x)