N, M = input().split()
M    = int(M)
N    = int(N)
tmp  = [[int(j) for j in input().split()] for i in range(M)]

S    = [tmp[i][0] for i in range(M)]
C    = [str(tmp[i][1]) for i in range(M)]


targ = -1

for i in range(10**(N-1), 10**N):
  tmp = 0
  str_i = str(i)
  for j in range(M):
    if str_i[S[j]-1] == C[j]:
      tmp += 1
  if tmp == M:
    targ = i
    break

print(targ)