N, M = map(int, input().split())
n = [-1 for i in range(N)]

judge = True
i = 0
while i < M:
	s, c = map(int, input().split())
	if n[s-1] == -1:
		n[s-1] = c
	else:
		if c != n[s-1]:
			judge = False

	i += 1

if N != 1 and n[0] == 0:
	judge = False

if n[0] == -1:
	n[0] = 1

if judge:
	num = 0
	for j in n:
		if j != -1:
			num += j
		num *= 10
	print(int(num/10))
else:
	print(-1)
