n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
	s,c=map(int,input().split())
	if a[s-1]==-1 or a[s-1]==c:
		if s==1 and c==0:
			print(-1)
			exit()
		else:
			a[s-1]=c
	else:
		print(-1)
		exit()
for i in range(n-1):
	if a[i]!=0:
		break
	else:
		print(-1)
		exit()
ans=0
for i in range(n):
	if a[-1-i]==-1:
		a[-1-i]=0
	ans+=a[-1-i]*(10**i)
print(ans)

