c=0
f=0
N, M = map(int, input().split())
list = []
for i in range(M):
    a,b=input().split()
    list.append((int(a), int(b)))

for j in range(M):
	if list[j][0]+list[j][1]==1 and N==1:
		f=2
		c+=1
if c==M:
	print(0)
elif c<M:
	print(-1)
			
if f!=2:
	for i in range(1000):
		f=0
		for j in range(M):
			if int(i/(10**(N-list[j][0])))%10 != list[j][1]:
				f=1
				break
		if f==0 and i>=10**(N-1):
			print(i)
			break
		
if f==1:
	print(-1)