n, m = (int(x) for x in input().split())
s, c = [], []

for i in range(m):
  _s, _c = (int(x) for x in input().split())
  s.append(_s)
  c.append(_c)

ans = ''
if n > m:
  print(-1)
else:
  for _n in range(1, n+1):
    try:
      ans += str(min([c[i] for i, _s in enumerate(s) if _s == _n]))
    except Exception:
      ans += '0'
  if len(ans) == n:
    print(ans)
  else:
    print(-1)