n,m=map(int,input().split())
sc=[tuple(map(int,input().split())) for _ in range(m)]
sc=list(set(sc))
a=[-1]*n
for i in range(len(sc)):
  if a[sc[i][0]-1]==-1:
    a[sc[i][0]-1]=sc[i][1]
  else:
    print(-1)
    exit()

ans=""
if a[0]==0:
  if n==1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
else:
  for i in range(len(a)):
    if a[i]==-1:
      ans+="0"
    else:
      ans+=str(a[i])
  print(ans)