N,M=map(int,input().split())
ans=[10]*N
for i in range(M):
	s,c=map(int,input().split())
	if ans[s-1]!=10 and ans[s-1]!=c:
		print('-1')
		break
	else:
		ans[s-1]=c
else:
	if ans[0]==0 and len(ans)>1:
		print('-1')
	else:
		for i in range(N-1):
			if ans[i+1]==10:
				ans[i+1]=0
		if ans[0]==10:
			ans[0]=1
		A=0
		for i in range(N):
			A+=ans[i]*10**(N-i-1)
		print(A)