#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N,M,A[100];
    cin>>N>>M;
    for (int i=0;i<N;i++){
        cin>>A[i];
    }
    for (int k=1;k<=M;k++){
        for (int i=0 ; i<N-1 ; i++){
            if (A[i] % k>A [i+1] % k) {
                swap(A[i],A[i+1]);
            }
        }
    }
    for (int i=0;i<N;i++){
        cout<<A[i]<<endl;
    }
    return 0;
}

