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

o=[1,1,0]
flag=[0,0,0]


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

if n==1:
  if (flag[0]!=0) or (flag[1]!=0):
    print("-1")
    exit()
  print(o[2])
  exit()
if n==2:
  if (flag[0]!=0):
    print("-1")
    exit()
  if (o[1]==0):
    print("-1")
    exit()
  print(o[1],end="")
  print(o[2])
  exit()
if n==3:
  if (o[0]==0):
    print("-1")
    exit()
  print(o[0],end="")
  if flag[1]==0:
    print(0,end="")
  else:
    print(o[1],end="")
  print(o[2])
