n, m = map(int, input().split())
a, b ,cnt, num= [0]*n, [0]*n, [0]*n, [0]*n
for i in range(m):
  a[i], b[i] = map(int, input().split())
  cnt[a[i]-1]+=1
  if cnt[a[i]-1]==2:
    if num[a[i]-1]!=b[i]:
      print(-1)
      exit()
  num[a[i]-1]=b[i]

ans=''
for i in num:
  ans+=str(i)
  ANS=int(ans)
if ans==str(ANS):
  print(int(ans))
else:
  print(-1)