import numpy as np
N,M=map(int,input().split())
A=np.zeros(N)
ans=0
for i in range(M):
  s,t=map(int,input().split())
  if s==1 and t==0:
    ans=1
  else:
    if A[s-1]==0:
      A[s-1]=t
    elif A[s-1]==t:
      A[s-1]=t
    else:
      ans=1
      
if A[0]==0:
  A[0]=1

if ans==1:
  print(-1)
else:
  for i in range(N):
    ans+=A[i]*(10**(2-i))
  print(int(ans))
  