n, m = map(int, input().split())
s = []
c = []
for i in range(m):
  sc = input().split()
  s.append(int(sc[0]))
  c.append(int(sc[1]))

num = -1
#print(s, c)
for i in range(10**n):
  for _s, _c in zip(s, c):
    if str(_c) not in str(i) or str(i).index(str(_c)) + 1 != _s:
      num = -1
      break
    num = i
  if num != -1:
    break
print(num)