#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<long long, long long>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, a;
cin >> n >> m;
vector<int> v(n);
vector<int> dist(1 << m, -1);
queue<int> q;
for (int i = 0; i < n; i++) {
cin >> a;
v[i] = a;
q.push(a);
dist[a] = 0;
}
while(!q.empty()) {
a = q.front();
q.pop();
for (int i = 0; i < m; i++) {
int b = a ^ (1 << i);
if (dist[b] == -1) {
dist[b] = dist[a] + 1;
q.push(b);
}
}
}
for (int i = 0; i < n; i++) {
a = v[i] ^ ((1 << m) - 1);
cout << m - dist[a] << " ";
}
cout << "\n";
return 0;
}