n, m = gets.chomp.split(" ").map(&:to_i) arr = n.times.map{gets.chomp.split(" ").map(&:to_i)} hash = Hash.new { |i,j| hash[j] = [] } arr.each do |x,y| hash[y] << x end ans = 0 hash.each do |color,box| hash_count = Hash.new(0) box.each do |i| hash_count[i] += 1 end an = hash_count.sort_by{|a,b| b} many = an.pop ans += (box.size-many[1]) end puts ans