n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
a=[-1]*n
ans=1
for i in range(len(sc)):
  if a[sc[i][0]-1]==-1:
    a[sc[i][0]-1]=sc[i][1]
  else:
    if a[sc[i][0]-1]!=sc[i][1]:
      ans=0
      break
ll=""
for j in range(n):
  if a[j]==-1:
    a[j]=0
  ll+=str(a[j])
if ans==0:
  print(-1)
else:
  if n!=len(str(int(ll))):
    print(-1)
    print(1)
  else:
    print(int(ll))