N, M = map(int, input().split())
S = [0]*N
for _ in range(M):
  s, c = map(int, input().split())
  if S[s-1] == c:
    continue
  elif S[s-1] == 0:
    S[s-1] = c
  elif S[s-1] != c:
    print(-1)
    exit()

if S[0] == '0' and len(S)==1:
  print(0)
  exit()
elif S[0] == '0':
  print(-1)
  exit()
print(''.join(map(str, (S))))