n, m  = gets.chomp.split.map(&:to_i)
number = []
n.times{number << gets.to_i}
1.upto(m){|k|
    1.upto(n-1){|s|
        if number[s-1] % k > number[s] % k
            temp = number[s-1]
            number[s-1] = number[s]
            number[s] = temp
        end        
    }
}
puts number

