N, M = map(int, input().split())
num_list = [0]*N

flag=True

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

  if (s == 1 and c == 0):
    print(-1)
    flag=False
    break

  if (num_list[s-1] == 0):
    num_list[s-1] = c
  else:
    if num_list[s-1] != c:
      print(-1)
      flag=False
      break

if flag:
  if num_list[0] == 0:
    num_list[0] = 1

  ans = ""
  for i in num_list:
    ans += str(i)

  print(ans)