#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  for (int k = 1; k <= M; k++) {
    int idx = 0;
    while (idx != N - 1) {
      if ((A[idx] % k) > (A[idx + 1] % k)) {
        int tmp = A[idx];
        A[idx] = A[idx + 1];
        A[idx + 1] = tmp;
        idx++;
      } else {
        idx++;
      }
    }
  }
  for (int i : A) {
    cout << i << "\n";
  }
  return 0;
}
