#include <iostream>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)
long long N, X; bool used[1 << 19];
vector<long long>E;
int main() {
cin >> N >> X;
if (X >= (1LL << N)) {
for (int i = 0; i < (1 << N); i++) E.push_back(i);
}
else {
for (int i = 0; i < (1 << N); i++) {
if (used[i] == true) continue;
E.push_back(i);
used[i] = true; used[i^X] = true;
}
}
cout << (int)E.size() - 1 << endl;
for (int i = 0; i < (int)E.size() - 1; i++) { if (i) printf(" "); printf("%d", (E[i + 1] ^ E[i])); } printf("\n");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojcHJhZ21hIHdhcm5pbmcgKGRpc2FibGU6IDQ5OTYpCgpsb25nIGxvbmcgTiwgWDsgYm9vbCB1c2VkWzEgPDwgMTldOwp2ZWN0b3I8bG9uZyBsb25nPkU7CgppbnQgbWFpbigpIHsKCWNpbiA+PiBOID4+IFg7CglpZiAoWCA+PSAoMUxMIDw8IE4pKSB7CgkJZm9yIChpbnQgaSA9IDA7IGkgPCAoMSA8PCBOKTsgaSsrKSBFLnB1c2hfYmFjayhpKTsKCX0KCWVsc2UgewoJCWZvciAoaW50IGkgPSAwOyBpIDwgKDEgPDwgTik7IGkrKykgewoJCQlpZiAodXNlZFtpXSA9PSB0cnVlKSBjb250aW51ZTsKCQkJRS5wdXNoX2JhY2soaSk7CgkJCXVzZWRbaV0gPSB0cnVlOyB1c2VkW2leWF0gPSB0cnVlOwoJCX0KCX0KCgljb3V0IDw8IChpbnQpRS5zaXplKCkgLSAxIDw8IGVuZGw7Cglmb3IgKGludCBpID0gMDsgaSA8IChpbnQpRS5zaXplKCkgLSAxOyBpKyspIHsgaWYgKGkpIHByaW50ZigiICIpOyBwcmludGYoIiVkIiwgKEVbaSArIDFdIF4gRVtpXSkpOyB9IHByaW50ZigiXG4iKTsKCXJldHVybiAwOwp9