N, M = map(int, input().split())
guess = [-1] * N
for i in range(M):
  s, c = map(int, input().split())
  s = s - 1
  if s == 0 and c == 0:
    print(-1)
    exit()
  if guess[s] == -1:
    guess[s] = c
  elif guess[s] == c:
    continue
  else:
    print(-1)
    exit()
for i in range(len(guess)):
  if guess[i] == -1:
    guess[i] = 0
res = map(str, guess)
print(''.join(res))