import sys
 
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
 
sc.sort()
ans = 0
d = 0
s = 0
 
if sc[0][1] == 0 and n != 1:
  print('-1')
  sys.exit()

if sc[0][0] != 1:
  ans += 10**(n-1)
 
for i in sc:
  if i[0] != d:
    d = i[0]
    s = i[1]
    ans += s * (10 ** (n-d))
  else:
    if i[1] != s:
      print('-1')
      sys.exit()
 
print(ans)