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
ans = 0
for i in range(M):
  if s[i]-1 != 0:
    keta[s[i]-1] = min(keta[s[i]-1], c[i])
  else:
    if c[i] == 0:
      continue
    else:
      keta[s[i]-1] = min(keta[s[i]-1], c[i])

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