# -*- coding: utf-8 -*-
# 157c
n, m = map(int, input().split())
s = []
c = []
for _ in range(m):
  _s, _c = input().split()
  s.append(int(_s))
  c.append(_c)

ret = -1
for i in range(10 ** 4):
  for _s, _c in zip(s, c):
    if len(str(i)) < _s or str(i)[_s - 1] != _c:
      ret = -1
      break
    ret = i
  if i == 702:
    print(i)
  if ret != -1:
    break
print(ret)
