N,M=map(int, input().split())
SC=[list(map(int, input().split())) for _ in range(M)]

countflag=[[0,0],[0,0],[0,0]]
ans=[0,0,0]

flag=0
for i in range(M):
	s,c=SC[i][0],SC[i][1]
	if N==3 and s==1 and c==0:
		flag=1
		break
	if N==2 and s==2 and c==0:
		flag=1
		break
		
	if countflag[s-1][0]==0 or (countflag[s-1][0]==1 and countflag[s-1][1]==c):
		countflag[s-1][0]=1
		countflag[s-1][1]=c
		ans[3-s]=c
	
	else:
		flag=1
		break

if flag==1:
	print(-1)
	
elif N==3 and flag==0:
	if ans[2]==0:
		print(100+ans[1]*10+ans[0])
	else:
		print(ans[2]*100+ans[1]*10+ans[0])

elif N==2 and flag==0:
	if ans[1]==0:
		print(10+ans[0])
	else:
		print(ans[1]*10+ans[0])
elif N==1 and flag==0:
	print(ans[0])
