# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=['0']*N
  for si,ci in zip(s,c):
    if res[si-1]== '0':
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()
  if res==['0']*N:
    print(-1)
    exit()
  su = int("".join(res))
  if su < 10**(N-1):
    print(-1)
    exit()
    
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()