import copy

n, m = map(int, input().split())
ans = [0]*n
ans_list = []
bns = copy.deepcopy(ans)

for _ in range(m):
  s, c = map(int, input().split())
  if ans[s-1] == 0:
    bns[s-1] = c

  elif ans[s-1] != 0 and ans[s-1] > c:
    bns[s-1] = c
  ans_list.append(bns)
  bns = copy.deepcopy(bns)
  
if n == 1:
  L=[str(a) for a in ans]
  print("".join(L))
  exit()

ans_list.sort()
if n >= 2:
  for ans in ans_list:
    if ans[0] != 0:
      L=[str(a) for a in ans]
      print("".join(L))
      exit()

print(-1)