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" or ans[sc[i][0] - 1] > str(sc[i][1]):
    ans[sc[i][0] - 1] = str(sc[i][1])

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