N, M = map(int, input().split())
SC = [list(map(int, input().split()))for i in range(M)]
ans=0
val=[""]*3
for i in range(M):
	if val[SC[i][0]-1] == "" or val[SC[i][0]-1] == SC[i][1]:
		val[SC[i][0]-1]=SC[i][1]
	else:
		print(-1)
		exit()
for i in range(N):
	if val[0]=="":val[0]=1
	if val[i]=="":val[i]=0
	ans+=val[i]*10**(N-i-1)
if val[i]==0:
	ans=-1
print(ans)
