def main():
  n, m = map(int, input().split())
  number = [-1] * n
  for i in range(m):
    s, c = map(int, input().split())
    if number[s-1] == -1 or number[s-1] == c:
      number[s-1] = c
    else:
      print(-1)
      return

  if number[0] == -1:
    number[0] = 1
  if number[0] == 0:
    print(-1)
    return
  for ans_value in number:
    if ans_value == -1:
      ans_value = 0
    print(ans_value, end="")
if __name__ == '__main__':
  main()