#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int N,M,Input = 0;
    vector<int> student;
    cin >> N >> M;
    
    for(int i = 0;i < N;i++){
        cin >> Input;
        student.push_back(Input);
    }
    
    for(int k = 1;k <= M;k++){
        for(int i = 0;i < N-1;i++){
            if(student[i] % k > student[i+1] % k){
                swap(student[i],student[i+1]);
            }
        }
    }
    
    for(int i = 0;i < student.size();i++){
        cout << student[i] << endl;
    }
    
    return 0;
}