loop do
  n = gets.to_i
  break if n == 0
  arr = gets.split(' ').map(&:to_i)

  count = 0
  (n-1).downto(0) do |i|
    max_idx = i
    0.upto(i) do |j|
      max_idx = j if arr[j] > arr[max_idx]
    end

    if max_idx != i
      arr[max_idx], arr[i] = arr[i], arr[max_idx]
      count += 1
    end
  end

  puts arr.join(' ')
  puts count
end