N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

A = [-1 for _ in range(N)]

for s, c in SC:
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] == c:
      pass
    else:
      print(-1)
      exit()

for i in range(M):
  if A[i] == -1:
    A[i] = 0

if A[0] == 0:
  print(-1)
  exit()

print(''.join(map(str, A)))