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

for i in range(M):
	
	if list[i][0]>N or (list[i][0]+list[i][1]==1 and N!=1):
		print(c)
		f=1
		break
	for j in range(i+1,M):
		if list[i][0]==list[j][0]:
			g=1
			if list[i][1]!=list[j][1]:
				print(c)
				f=1
				break
	if f==1:
		break
	if g==0:
		d+=list[i][1]*(10**(N-list[i][0]))
	g=0
if f==0:
	if d-10**(N-1)<0 or (d==0 and N!=1)
		print(d+10**(N-1))
	else:
		print(d)