N,M=map(int,input().split())
A=[]
B=[]
for _ in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  
if N  == 3:
	Nint = [0]*3
elif N  == 2:
	Nint = [0]*2
else:
	Nint = [0]

for i in range (0, M):
	if int(A[i]) > N:
		print(-1)
		quit()
	elif A[i] == 1 and B[i] == 0:
		print(-1)
		quit()
	elif Nint[A[i]-1] == 0:
		Nint[A[i]-1] = B[i]			          
	elif Nint[A[i]-1] == B[i]:
		continue
	else:
		print(-1)
		quit()
if Nint[0] == 0:
	Nint[0] = 1 

Bint = str()

for i in range (0, len(Nint)):
	Bint = Bint+str(Nint[i])

print(int(Bint))