n, m = gets.strip.split.map(&:to_i)
conds = m.times.map { gets.strip.split }

ans = -1

((10 ** n.pred)..(10 ** n).pred).each do |i|
  cs = i.to_s.chars

  flag = conds.all? do |s, c|
    cs[s.to_i - 1] == c
  end

  if flag
    ans = i
  end
end

puts(ans)
