N, M = map(int, input().split())

S, C = [], []
for i in range(M):
  s, c = map(int, input().split())
  S += [s-1]
  C += [str(c)]
  
for i in range(10**(N-1), 10**N):
  flag = 1
  i_str = str(i)
  for m in range(M):
    if i_str[S[m]] != C[m]:
      flag = 0
      break
  if flag:
    print(i)
    break
else:
  print(-1)