n, m = map(int, input().split())
ans = [0]*n
cnt = [0]*n

for _ in range(m):
  s, c = map(int, input().split())
  if ans[s-1] == 0 and cnt[s-1]==0:
    ans[s-1] = c
    cnt[s-1] = 1
  elif ans[s-1] == 0 and cnt[s-1]!=0:
    continue
  elif ans[s-1] != 0 and ans[s-1] > c:
    ans[s-1] = c

if n == 1:
  L=[str(a) for a in ans]
  print("".join(L))
elif n >= 2 and ans[0] != 0:
  L=[str(a) for a in ans]
  print("".join(L))
else:
  print(-1)