n,m = map(int,input().split())

o=[10]*3

for _ in range(0,m):
  s,c = map(int,input().split())
  if o[s-1]!=10:
    if o[s-1]!=c:
      print("-1")
      exit()
  o[s-1]=c

if o[0]==0:
  print("-1")
  exit()
if o[0]==10 and o[1]==10:
  print(o[2])
  exit()

if o[0]==10:
  print(o[1],end="")
  print(o[2])
  exit()

for i in range(0,3):
  if o[i]==10:
    print(0,end="")
  else:
    print(o[i],end="")
