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

number = ["0"] * N
number[0] = "1"
box = []

ok = True
for i in range(M):
  if sc[i][0] not in box:
    number[sc[i][0] - 1] = str(sc[i][1])
    box.append(sc[i][0])
  elif sc[i][0] in box:
    if number[sc[i][0] - 1] != str(sc[i][1]):
      ok = False

if ok:
  if number[0] == "0" and N > 1:
    ok = False

print("".join(number) if ok else -1)