#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;

int main(){
	//ゼッケンの交換
	
	int n, m;
	cin >> n >> m;
	int A[100];
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		A[i] = a;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j < n; j++) {
			if (A[j - 1] % i > A[j] % i) {
				int temp = A[j - 1];
				A[j - 1] = A[j];
				A[j] = temp;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}

	//クリスマスパーティー
	/*
	int n, m;
	cin >> n >> m;

	int A[100];
	for (int i = 0; i < m; i++) {
		cin >> A[i];
	}

	int P[100];
	for (int i = 0; i < n; i++) {
		P[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		int x = 0;
		for (int j = 0; j < n; j++) {
			int b;
			cin >> b;
			if (b == A[i]) {
				P[j]++;
			}
			else {
				x++;
			}
			if (j == n - 1) {
				P[A[i]-1] += x;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << P[i] << endl;
	}
	*/
	//シーザー暗号
	/*
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A'||s[i] == 'B'||s[i]=='C') {
				s[i] += 23;
				cout << s[i];
			}
		else {
			s[i] -= 3;		
			cout << s[i];
		}		
	}
	cout << endl;
	*/

	//ABC
	 //happy barthday
	/*int a, b;
	cin >> a >> b;
	if (max(a, b) > 8) {
		cout << ":(";
		return 0;
	}
	cout << "Yay!";
	*/
	//#2
	/*int d, n;
	cin >> d >> n;
	if (n == 100) {
		n++;
	}
	cout << n*pow(100, d) << endl;
	*/
	//#3
	/*
	int n;
	cin >> n;
	int x = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2==0)
			x++;
	}
	int ans=0;
	
	for(int i = 1; i <= x; i++) {
		ans += n - i;
	}
	cout << ans << endl;
	*/

	//未提出者は誰だ

	
		//Attention
		/*
	int n;
	string s;
	cin >> n >> s;
	
	vector<int> X;
	for (int i = 0; i < n; i++) {
		X.push_back(0);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (s[j] == 'W')
				X[i]++;
		}
		for (int j = i + 1; j < n; j++) {
			if (s[j] == 'E') {
				X[i]++;
			}
		}
	}

		int ans = X[0];
		for (int i = 0; i < n - 1; i++) {
			if (X[i] > X[i + 1]) {
				ans = X[i + 1];
			}
		}
		cout << ans << endl;
		*/
		//Cut and Count
		/*
		int n;
		string s;
		cin >> n >> s;
		int C[100];

		for (int i = 0; i < 100; i++) {
			C[i] = 1;
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				for (int k = i; k < n; k++) {
					if (s[j] == s[k])
						C[i]++;
				}
			}
		}

		int ans=C[0];
		for (int i = 0; i < 99; i++) {
			if (C[i] < C[i + 1])
				ans = C[i + 1];
		}
		cout << ans / 2 << endl;
		*/
		//
		/*
		int a, b;
		cin >> a >> b;
		int x;
		x = max(a + b, a - b);
		x = max(x, a*b);
		cout << x << endl;
		*/
		//はじめてのあっとこーだー
		/*
		int a, b, c;
		cin >> a >> b >> c;
		string s;
		cin >> s;

		cout << (a + b + c) << " " << s <<endl;
		*/
		//気象予報士
		/*
		int h, w;
		cin >> h >> w;
		char x[100][100];
		int ans[100][100];
		for (int i = 0; i < h; i++) {
			string a;
			cin >> a;
			for (int j = 0; j < w; j++) {
				x[i][j] = a[j];
				ans[i][j] = -1;
			}
		}
		for (int i = 0; i < w-1; i++) {
			for (int j = 0; j < h; j++) {
				for (int k = 0; k < w; k++) {
					if (x[j][k-i] == 'c'&&ans[j][k]==-1)
						ans[j][k] = i;
				}
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j=0; j < w; j++) {
				cout << ans[i][j];
				if (j == w-1) break;
				cout << " ";
			}
			cout << endl;
		}
		*/
		//サッカー
		/*
		int N;
		cin >> N;
		int P[100];
		for (int i = 0; i < 100; i++) {
			P[i] = 0;
		}
		for (int i = 0; i < N*(N - 1) / 2; i++) {
			int a, b,c,d;
			cin >> a >> b >> c >> d;
			if (c > d)
				P[a] += 3;
			if (c == d) {
				P[a]++;
				P[b]++;
			}
			if (c < d)
				P[b] += 3;
		}
		int Q[100];
		for (int i = 0; i < N; i++) {
			Q[i] = P[i];
		}
		sort(Q, Q + 100);
		reverse(Q, Q + 100);
		int Ans[100];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (P[i] == Q[j]) {
					Ans[i] = j+1;
				}
			}
		}
		for (int i = 0; i < N; i++) {
			cout << Ans[i] << endl;
		}
		*/
		//レシート
		/*
		int N;
		int ans[5];
		int a;
		int i = 0;
		while (true)
		{
			cin >> N;
			if (N == 0) break;
			for (int j = 0; j < 9; j++) {
				cin >> a;
				N -= a;
			}
			ans[i] = N;
			i++;
		}
		for (int k = 0; k < 5; k++)
			cout << ans[k] << endl;
		*/
		//コンテスト	
		/*
		int W[10], K[10];
		for (int i = 0; i < 10; i++) {
			cin >> W[i];
		}
		for (int i = 0; i < 10; i++) {
			cin >> K[i];
		}
		sort(W, W + 10);
		reverse(W, W + 10);
		sort(K, K + 10);
		reverse(K, K + 10);
		cout << W[0] + W[1] + W[2] << " " << K[0] + K[1] + K[2] << endl;
		*/
		//ポイントカード
		/*
		int N, M;
		cin >> N >> M;
		int a;
		int A[5000];
		int b = 0;
		int x = 0;
		for (int i = 0; i <  M; i++) {
			cin >> a;
			if (a < N) {
				A[x]=a;
				x++;
			}
			else
			{
				b++;
			}
			cin >> a;
		}
		int sum = 0;
		if (b < M - 1) {
			sort(A, A+x);
			reverse(A, A+x);
			for (int i = 0; i < M - 1 - b; i++) {
				sum += N - A[i];
			}
		}
		cout << sum << endl;
		*/
		//合計時間
		/*
		int sum=0, n;
		for (int i = 0; i < 4; i++) {
		cin >> n;
		sum += n;
		}
		cout << sum / 60 << endl;
		cout << sum % 60 << endl;
		//平均点
		/*
		int P[5];
		int sum=0;
		for (int i = 0; i < 5; i++) {
		cin >> P[i];
		if (P[i] < 40) P[i] = 40;
		sum += P[i];
		}
		cout << sum / 5 << endl;
		*/
		//投票
		/*
		int N, M;
		cin >> N >> M;
		int A[1000], vote[1000];
		for (int i = 0; i < N; i++) {
		cin >> A[i];
		vote[i] = 0;
		}
		int b;
		for (int i = 0; i < M; i++) {
		cin >> b;
		for (int j = 0; j < N; j++) {
		if (A[j] <= b) {
		vote[j]++;
		break;
		}
		}
		}
		int temps = 0, ans;
		for (int i = 0; i < N; i++) {
		if (vote[i] > temps) {
		temps = vote[i];
		ans = i;
		}
		}
		cout << ans + 1 << endl;
		*/
		//2.すごろく	
		/*
		int n;
		cin >> n;
		int A, _A = 1;
		int k = 0;
		int A_count[100];
		A_count[0] = 1;
		for (int i = 0; i < n; i++)
		{
		cin >> A;
		if (A == 1)
		{
		if (A == _A)
		{
		A_count[k]++;
		}
		else
		{
		k++;
		A_count[k] = 2;
		}
		}
		_A = A;
		}
		sort(A_count, A_count + k + 1);
		cout << A_count[k] << endl;
		*/
		//タイムカード
		/*
		int t[2][3];
		int x[3][3];
		for (int n=0; n < 3; n++)
		{
		for (int i=0; i < 2; i++)
		for (int k=0; k < 3; k++)
		cin >> t[i][k];

		for (int m = 2; m >= 0; m--)
		{
		x[n][m] = t[1][m] - t[0][m];
		if (t[0][m] > t[1][m])
		{
		x[n][m] += 60;
		t[1][m - 1]--;
		}
		}
		}
		for (int n= 0; n < 3; n++)
		{
		cout << x[n][0] << ' ' << x[n][1] <<' '<< x[n][2] << endl;
		}
		*/


		return 0;
	}


Measured memory_bytes: 3072