#include<iostream>
using namespace std;

int main(){
	int N,M;
	int a[100]; 
	int i=0;
	cin>>N>>M;
	for(int coun =0;coun<N;coun++){
		cin>>a[coun];
	}
	for(int k =1;k<=M;k++){
		i=0;
		while(true){			
			if((i+1)==N){
				break;
			}		
			if(((a[i]%k)>(a[i+1]%k))){
				int r;
				r = a[i+1];
				a[i+1]=a[i];
				a[i] = r;
			}
			i++;
		}
	}
	for(int coun =0;coun<N;coun++){
		cout<<a[coun]<<endl;
	}
}