N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

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

if ans == "-1":
  print(ans)
else:
  print("".join(ans) if ans[0] != "0" or N == 1 else -1)