N, M = map(int,input().split())
s, c = [0]*M, [0]*M
for i in range(M):
  s[i], c[i] = map(int,input().split())

keta = [10]*N
for i in range(M):
  if keta[s[i]-1] == 10:
    keta[s[i]-1] = c[i]
  else:
    if keta[s[i]-1] != c[i]:
      print(-1)
      exit()
ans = 0
for i in range(N):
  if keta[0] == 0 and N != 1:
    print(-1)
    exit()
  elif i == 0 and keta[0] == 10:
    ans += pow(10,N-1)
  elif keta[i] != 10:
    ans += keta[i]*pow(10,N-i-1)
print(ans)