n,m = map(int,input().split())
s = [0] * m
c = [0] * m
def ret():
	print(0)
	return
for i in range(m):
	s[i],c[i] = map(int,input().split())
def ret1():
	ans = 1000
	for i in range(10**(n-1),10**n):
		flag = 1
		for j in range(m):
			if i//(10**(n-s[j]))%10 != c[j]:
				flag = 0
		if flag == 1:
			print(i)
			return
	print(-1)
	return
if m == 1 and n == 1 and c[0] == 0:
	ret()
else:
	ret1()
