#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int student = 0 ;
    int baton = 0 ;
    int bibs[101] = {0} ;

    cin >> student >> baton ;
    for ( int i = 0 ; i < student ; i++ )
    {
        cin >> bibs[i] ;
    }

    for ( int i = 1 ; i <= baton ; i++ )
    {
        for ( int j = 0 ; j < student ; j++ )
        {
            if ( (bibs[j] % i) > (bibs[j+1] % i) && j != student-1 )
            {
                swap( bibs[j],bibs[j+1] ) ;
            }
        }
    }

    for ( int i = 0 ; i < student ; i++ )
    {
        cout << bibs[i] << endl ;
    }

    return 0 ;
}