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

int main()
{
	int n, m;
	int ary[101];

	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> ary[i];

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j < n; j++)
		{
			if ((ary[j] % i) > (ary[j + 1] % i)) swap(ary[j], ary[j + 1]);
		}
	}
	for (int i = 1; i <= n; i++) cout << ary[i] << endl;

	return 0;
}