n,m=map(int,input().split())
a=[0]*n
for i in range(m):
  s,c=map(int,input().split())
  if a[n-s]==0:
    a[n-s]=c
  else:
    if c!=a[n-s]:
      print(-1)
      exit()
  if a[0]==0:
    print(-1)
      exit()
ans=""
for i in a:
  ans+=i
print(ans)