#include <iostream>
using namespace std;

int main(void) {
    int N,M;cin>>N>>M;
    int A[N+1];
    A[0] = 0;
    for (int i = 1; i <= N; i++) cin>>A[i];
    for (int k = 1; k <= M; k++) {
        for (int i = 1; i <= N; i++) {
            if (i < N) {
                if (A[i] % k > A[i + 1] % k) swap(A[i],A[i+1]);
            }
        }
    }
    for (int i = 1; i <= N; i++) cout << A[i] << endl;
    return 0;
}
