n, m = map(int, input().split())
a = list([0] * n)

for _ in range(m):
  s, c = map(int, input().split())
  if a[s-1] == 0:
    a[s-1] = c
  elif a[s-1] > c:
    a[s-1] = c

a = ''.join(map(str, a))

if len(str(int(a))) != n:
  print('-1')
else:
  print(int(a))