res = '-1'
N, M = [int(x) for x in input().split(' ')]
r = ['0' for _ in range(N)]
SC = sorted(list(set([input() for _ in range(M)])), key=lambda x: x[0])
before_s = -1
for sc in SC:
  s, c = sc.split(' ')
  s = int(s)
  if s == before_s:
    break  # -1
  if s > N:
    break  # -1
  before_s = s
  r[s-1] = c
else:
  if N == 1:
    if r[0] == r[1] == '0':
      res = r[2]  # ok
  elif N == 2:
    if r[0] == '0' and r[1] != '0':
      res = ''.join(r[1:])  # ok
  else:
    if r[0] != '0':
      res = ''.join(r)  # ok
print(res)