import numpy as np

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

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

res += (res == -1) * 1

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