from sys import exit

n,m = map(int,input().split())
A=[-1]*3

cnt=0
for _ in range(m):
	s,c=map(int,input().split())
	if A[s-1]!=c and A[s-1]!=-1:
		cnt=1
	else:
		A[s-1]=c

if cnt==1 or A[0]==0:
	print("-1")
	exit()
	
if A[0]==-1:
	A[0]=1

res=0
for i in range(n):
	if A[i]==-1:
		A[i]=0
	res+=A[i]*(10**(n-i-1))

print(res)