N, M = gets.split.map(&:to_i)
A = Array.new(N)
N.times do |i|
    A[i]=gets.to_i
end
[*1..M].each do |k|
    N.times do |i|
        break if i == N-1
        p1 = A[i]%k
        p2 = A[i+1]%k
        if p1 > p2 then
            tmp = A[i]
            A[i] = A[i+1]
            A[i+1] = tmp
        end
    end
end
A.each{|a| p a}
