N, M = gets.split.map(&:to_i)

from = 0
to = (10**N) - 1

check = M.times.to_a.map do
  gets.split.map(&:to_i)
end

from.upto(to) do |i|
  s = i.to_s
  c = check.all? do |v|
    s.size >= v[0] && s[v[0] - 1].to_i == v[1]
  end
  if c
    print i
    exit
  end
end

print(-1)
