import sys
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

k=0
t=0
x=0
a=[0]*n

for i in table:
	k=i[0]
	t=i[1]
	if k>n:
		print(-1)
		sys.exit()
	b=a[k-1]
	if k==1 and t==0:
		x=-1
	elif k>n:
		x=-1
	if b!=t and b!=0:
		x=-1
	else:
		a[k-1]=t
if len(a)==3 and x==0:
	if a[0]==0:
		a[0]=1
	x=a[0]
	y=a[1]
	z=a[2]
	print(x*100+y*10+z)
if len(a)==2 and x==0:
	if a[0]==0:
		a[0]=1
	x=a[0]
	y=a[1]
	print(x*10+y)
if len(a)==1 and x==0:
	x=a[0]
	print(x)
if x==-1:
	print(-1)