N,M = map(int,input().split())
S = [0] * M
C = [""] * M

for i in range(M):
  s,C[i] = input().split()
  S[i] = int(s) - 1

for i in range(1000):
  s = str(i)
  if len(s) != N:
    continue
  for j in range(M):
    if s[S[j]] != C[j]:
      break
  else:
    print(i)
    break
else:
  print(-1)
  