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

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