#include <bits/stdc++.h>
using namespace std;
int n, numBan, bitIdxBan;
int fillBanBit(int x) {
  if (bitIdxBan == 0) return x << 1;
  int left = (x >> bitIdxBan) << (bitIdxBan + 1);
  int right = x & ((1 << bitIdxBan) - 1);
  return left + right;
}
void generateList(int bitPos) {
  if (bitPos >= 0) {
    generateList(bitPos - 1);
    cout << fillBanBit(1 << bitPos) << " ";
    generateList(bitPos - 1);
  }
}
void outerInit() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  auto fi = new ifstream("test.inp");
  if (*fi) {
    cin.rdbuf(fi->rdbuf());
  }
}
void readData() {
  cin >> n >> numBan;
  bitIdxBan = __builtin_ctz(numBan);
}
void initData() {}
void solveData() {
  if (numBan < (1 << n)) {
    --n;
  } else {
    bitIdxBan = n + 1;
  }
  cout << (1 << n) - 1 << "\n";
  generateList(n - 1);
}
int main() {
  outerInit();
  readData();
  initData();
  solveData();
}
