N,M=map(int,input().split())#N桁M条件
A=[0 for _ in range(N)]
if N==1:
  B=-1
  for _ in range(M):
    s,c=map(int,input().split())#左からs番目がc
    if B==-1:
      B=c
    elif B==c:
      pass
    else:
      print(-1)
      exit()
  print(B)
if N>1:
  for _ in range(M):
    s,c=map(int,input().split())#左からs番目がc
    if s==1 and c==0:
      print(-1)
      exit()
    elif A[s-1]==0:
      A[s-1]=c
    elif A[s-1]==c:
      pass
    elif s==1 and c==0:
      print(-1)
      exit()
    else:
      print(-1)
      exit()
  if A[0]==0:
    A[0]=1
  a=0
  for i in range(N):
    a+=A[i]*10**(N-1-i)
  print(a)