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) and (o[s-1]!=c):
    print("-1")
    exit()
  o[s-1]=c

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