N, M = map(int, input().split())

sc = [-1] * N
for _ in range(M):
  s, c = map(int, input().split())
  s -= 1
  if s == 0 and c == 0:
    print(-1)
    exit(0)
  if sc[s] != -1 and sc[s] != c:
    print(-1)
    exit(0)
  sc[s] = c

ans = ""
for i in range(N):
  if sc[i] == -1:
    ans += str(0)
  else:
    ans += str(sc[i])

print(ans)
