n, k = gets.split.map(&:to_i) ss = n.times.map { gets.chomp } ts = n.times.map { gets.chomp } tsi = ts.map.with_index.to_h ss.each_with_index do |nm, i| if (tsi[nm] - i) % k != 0 puts 'No' exit end end puts 'Yes'