#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
bool poredi(const pair<long long,int>&a,const pair<long long,int>&b){
return a.first>b.first;
}
bool indeks(const pair<long long,int>&a,const pair<long long,int>&b){
return a.second<b.second;
}
int main()
{
    long long n;
    int k;
cin>>n;
cin>>k;
vector< pair<long long,int> >a(k);
vector<long long>b(k);
for(int i=0;i<k;i++){
    cin>>a[i].first;
    a[i].second=i;
    b[i]=a[i].first;
}
sort(b.begin(),b.end(),greater<long long>());
sort(a.begin(),a.end(),poredi);
for(int i=0;i<k;i++){
    for(int j=i+1;j<k;j++){
        if(b[i]%b[j]==0){

            a[i].first^=b[j];

        }
    }



 }


sort(a.begin(),a.end(),indeks);
for(int i=0;i<k;i++){
 cout<<a[i].first<<" ";
}
    return 0;
}