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

int main()
{
	int n, m;
	int a[100];

	cin >> n >> m;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int j = 1; j <= m; j++)
		for (int i = 0; i < n - 1; i++)
			if ((a[i] % j) > (a[i + 1] % j))
				swap(a[i], a[i + 1]);

	for (int i = 0; i < n; i++)
		cout << a[i] << endl;

	return 0;
}
