
def main():
  n, m = map(int, input().split(' '))

  num_list = [0] * n
  done_list = [-1] * n

  for _ in range(m):
    s, c = map(int, input().split(' '))

    current = int(num_list[s - 1])

    if done_list[s - 1] != -1 and done_list[s - 1] != current:
      print(-1)
      exit()

    num_list[s - 1] = c
    done_list[s - 1] = c

  num = "".join(map(str, num_list))
  print(-1 if num[0] == "0" else num)

main()
