import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
for  i in range(len(arr)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)