n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
ans = -1
for i in range(1000):
	s = str(i)
	if len(s) == n:
		flag = 0
		for (x, y) in a:
			if int(s[x-1]) != y:
				flag = 1
		if flag == 0:
			ans = i
			break

print(ans)