n, m = map(int, input().split())

tmp = ["0" for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  if int(tmp[int(s)-1]) >= int(c) or int(tmp[int(s)-1]) == 0:
    tmp[int(s)-1] = c

ans = int("".join(tmp))
if len(str(ans)) == n:
  print(ans)
else:
  print(-1)
