import numpy as np

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

res = np.zeros(N, dtype=np.int)
for i in range(M):
  keta, v = input().split(' ')
  keta = int(keta) - 1
  v = int(v)
  if res[keta] < v:
    res[keta] = v

if res[0] > 0:
  x = [str(x) for x in res]
  x = ''.join(x)
  print(x)
else:
  print(-1)