n,m=map(int,input().split())
d={}
for i in range(m):
  s,c=map(int,input().split())
  d[s]=c
  
if n==1 and 1 in d:
  print(d[s])
elif n==2 and 1 in d and d[1] !=0:
  if 2 in d:
    print("{}{}".format(d[1],d[2]))
  else:
    print("{}0".format(d[1]))
elif n==3 and 1 in d and d[1] !=0:
  if 2 in d and 3 in d:
    print("{}{}{}".format(d[1],d[2],d[3]))
  elif 2 not in d and 3 not in d:
    print("{}00".format(d[1]))
  elif 2 not in d and 3 in d:
    print("{}0{}".format(d[1],d[3]))
  elif 2 in d and 3 not in d:
    print("{}{}0".format(d[1],d[2]))
else:
  print(-1)