#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int student;
	int bibs[101];
	int baton;
	int i, j;
	
	cin >> student;
	cin >> baton;
	
	for (i = 1; i <= student; i++){
		cin >> bibs[i];
	}
	for (j = 1; j <= baton; j++){
		for (i = 1; i + 1 <= student; i++){
			if (bibs[i] % j > bibs[i+1] % j){
				swap(bibs[i],bibs[i+1]);
			}
		}
	}
	
	for (i = 1; i <= student; i++){
		cout << bibs[i] << endl;
	}
	
	return (0);
}