res = '-1'
N, M = [int(x) for x in input().split(' ')]
r = [0 for _ in range(N)]
SC = list(set([input() for _ in range(M)]))
SC = sorted([[int(x) for x in sc.split(' ')] for sc in SC], key=lambda x: x[0])

before_s = -1
for s, c in SC:
  if s == before_s:
    break  # -1
  before_s = s
  r[s-1] = c
else:
  if N == 1:
    if r[0] == r[1] == 0:
      res = str(r[2])  # ok
  elif N == 2:
    if r[0] == 0 and r[1] != 0:
      res = ''.join([str(x) for x in r[1:]])  # ok
  else:
    if r[0] != 0:
      res = ''.join([str(x) for x in r])  # ok
print(res)