#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int N [k];
    vector<int> N1;
    for (int i = 0; i < k; i++)
    {
        cin >> N[i];
        N1.push_back (N[i]);
    }
    sort (N1.begin(), N1.end());
    for (int i = 0; i < k; i++)
    {
        int Xor = 0;
        vector <int>::iterator it = lower_bound (N1.begin(), N1.end(), N[i]);
        for (int j = 0; j < (it-N1.begin()); j++)
            if (N[i]%N1[j]==0) Xor=Xor^N1[j];
        Xor = Xor^N[i];
        cout << Xor << " ";
    }
    return 0;
}