#include<bits/stdc++.h>

using namespace std;

#define int long long

void solve(){
    int n, k;
    cin>>n>>k;
    vector<int> d(k);
    for(int i = 0;i<k;i++) cin>>d[i];
    unordered_map<int, int> mp;
    vector<int> d2 = d;
    sort(d2.begin(), d2.end());
    for(int i = 0;i<k;i++){
        mp[d2[i]] = d2[i];
        for(int j = i-1;j>=0;j--){
            if((d2[i])%(d2[j])==0){
                mp[d2[i]]^=(d2[j]);
            }
        }
    }
    for(int i = 0;i<k;i++){
        cout<<mp[d[i]]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}