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 < len(sc):
  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()

if m == 0:
  if n == 1:
    print("0")
    exit()
  elif n == 2:
    print("10")
    exit()
  else:
    print("100")
    exit()
    
    
ans = 0
for i in range(len(sc)):
  k = int(sc[i][0])
  ans += int(sc[i][1]) * (10 ** (n-k))

print(ans)