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 or 4 in s or 5 in s:
  print(-1)
else:
  for _n in range(1, n+1):
    if len([c[i] for i, _s in enumerate(s) if _s == _n]) == 0:
      ans += '0'
    else:
      ans += str(min([c[i] for i, _s in enumerate(s) if _s == _n]))

  if len(ans) == n and ans[0] != '0':
    print(ans)
  else:
    if ans == '0':
      print(0)
    else:
      print(-1)