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

s = [-1] * M
c = [-1] * M

for m in range(M):
  s[m], c[m] = map(int, input().split(' '))

for i in range(0, 10 ** N):
  if (all(len(str(i)) >= s[m] - 1 and str(i)[s[m]-1] == str(c[m]) for m in range(M))):
    print(i)
    exit()

print(-1)
