//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0620?year=2016

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

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

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

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

/*
 *
 */
