N, M = map(int,input().split())
answer = [0]*M
ae = 0

for i in range(M):
  s,c = map(int,input().split())
  if answer[-s] == 0:
    answer[-s] = c
  elif answer[-s] != 0 and answer[-s] != c:
    print(-1)
    ae = 1
    break
if ae == 0 and answer[-M] == 0:
  print(-1)
  ae = 1
elif ae == 0:
  for i in range(M):
    print(answer[-(i+1)],end='')