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

s, c = [], []
for _ in range(m):
  s_, c_ = map(int, input().split())
  s.append(s_)
  c.append(c_)

flg = False
for i in range(10**n):
  for j in range(m):
    if str(i)[s[j]-1] != str(c[j]):
      break
  else:
    print(i)
    flg = True
    break
if not flg:
  print(-1)