n, m = map(int, input().split())
sc = [input().split() for _ in range(m)]
sc = list(map(list, set(map(tuple, sc))))
sc.sort()

if n < m:
  print("-1")
  exit()
else:
  for i in range(len(sc)-1):
    if sc[i][0] == sc[i+1][0]:
      print("-1")
      exit()
      
for i in range(len(sc)):
  if int(sc[i][0]) != n and int(sc[i][1]) == 0:
    print("-1")
    exit()

    
ans = 0
for i in range(len(sc)):
  k = int(sc[i][0])
  ans += int(sc[i][1]) * (10 ** (n-k))

print(ans)