#include <iostream>
#include <vector>

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    for (int k = 1; k <= m; ++k) {
        for (int i = 0; i + 1 < n; ++i) {
            if (xs[i] % k > xs[i + 1] % k) {
                std::swap(xs[i], xs[i + 1]);
            }
        }
    }

    for (auto x : xs) std::cout << x << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}

