N,M=map(int,input().split())
S=[]
C=[]
A=[0]*N
for i in range(M):
	x,y=map(int,input().split())
	S.append(x)
	C.append(y)
for i in range(M):
	if A[(S[i]-1)]==0:
		A[(S[i]-1)]=C[i]
	if A[(S[i]-1)]!=0:
		if A[(S[i]-1)]!=C[i]:
			print(-1)
			exit()
ans=0
for i in range (1,N+1):
	ans+=A[-i]*10**(i-1)
if len(str(ans))!=N:
	print(-1)
else:
	print(ans)