N, M = map(int, input().split())
s = [None] * M
c = [None] * M
for i in range(M):
  s[i],c[i] = map(int, input().split())

flag = False
for i in range(10**(N-1), 10**N):
  count = 0
  for j in range(M):
    if str(i)[s[j]-1] != str(c[j]):
      break
    else:
      count += 1
  if count == M:
    flag = True
    print(i)
    break
if not flag:
  print(-1)