def fuga(check_dict, check_str):
  for j, num_str in enumerate(str(check_str)):
    if(not(j in check_dict)):
      continue
    if(check_dict[j] != int(num_str)):
      return False
  return True

N,M = list(map(int, input().split()))
li = [list(map(int, input().split())) for _ in range(M)]
check = {}
for s,c in li:
  if(s-1 in check):
    if(check[s-1] != c):
      print(-1)
      exit()
  check[s-1] = c

if(N == 1):
  for i in range(9):
    if(fuga(check, i)):
      print(i)
      exit()
  print(-1)
  exit()
for i in range(10**(N-1), 10**(N)):
  if(fuga(check, i)):
    print(i)
    exit()
print(-1)
