def acceptable?(n, d, sc)
  n_ = n.to_s.rjust(d, '0')

  sc.reduce(n.to_s.length == d) do |acc, cur|
    s, c = cur
    acc && n_[s-1] == c.to_s
  end
end

d, m = gets.chomp.split(" ").map(&:to_i)
sc = (1..m).map { gets.chomp.split(" ").map(&:to_i) }

ans = -1
(1..999).each do |n|
  if acceptable?(n, d, sc)
    ans = n
    break
  end
end

puts ans
