n, m = list(map(int, input().split()))

d = [0] * n
r = 0

for i in range(m):
  s, c = list(map(int, input().split()))
  if (d[s-1] != 0) and (d[s-1] < c):
    r = -1
    break
  else:
    d[s-1] = c

if (r==-1):
  print(r)
else:
  dd = int(''.join(map(str, d)))
  if len(str(dd))==n:
    print(dd)
  else:
    print(-1)
