#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool stepen2(unsigned long long n){
long long k = log2(n);
if ( log2(n) == log2(n) ){
    return true;
}
return false;
}

unsigned long long f( unsigned long long n ){
if (n == 1) return 1;
if ( n == 2 ) return 3;
if ( n == 3 ) return 2;
if ( n == 4 ) return 7;
if ( n == 5 ) return 4;
if ( n == 6 ) return 6;
if ( n == 12 ) return 14;
if ( stepen2(n) == true)
    return 2*n - 1;
if( n%4 == 2 )
    return 2*f(n)^f(n);
return n-1;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
unsigned long long n;
long long k;
cin >> n >> k;
unsigned long long d[k+1];
for ( long long i = 1; i < k+1; i++ ){
    cin >> d[i];
}
for ( long long i = 1; i <= k; i++ ){
    cout << f(d[i]) << " ";
}
return 0;
}