import sys

N, M = [int(x) for x in input().split()]
guess = [-1] * (N + 1)
check = True
for i in range(M):
  s, c = [int(x) for x in input().split()]
  if guess[s] != -1 and guess[s] != c:
    check = False
  else:
    guess[s] = c


if guess[1] <= 0 :
  check = False
      
if not check:
  print(-1)
  sys.exit()
  
result = 0
y = N
for i in range(1, N+1):
  val = 0 if guess[i] == -1 else guess[i]
  result += 10 ** (y-1) * val
  y -= 1

print(result)