n, m = map(int, input().split())
a = []
for i in range(m):
	s,c = map(int, input().split())
	a.append([s,c])

for i in range(10**(n-1),10**n):
	if all(str(i)[s-1] == str(c) for s,c in a):
		print (i)
		exit()
print (-1)