#include <bits/stdc++.h>
using namespace std;
int ar[300001] = {}, cr = 0, tcr = 0;
bool bt[300001] = {};
int main() {
  int n, x;
  cin >> n >> x;
  bt[x] = 1;
  for (int i = 1; i < (1 << n); i++) {
    if (!bt[i]) {
      ar[cr++] = i;
      if (x < (1 << n)) {
        ar[cr - 1] = i ^ x;
      }
      bt[i] = 1;
      bt[i ^ x] = 1;
    }
  }
  for (int i = 0; i < cr - 1; i++) {
    tcr ^= ar[i];
    ar[i + 1] ^= tcr;
  }
  cout << cr << "\n";
  for (int i = 0; i < cr; i++) {
    cout << ar[i];
    if (i < cr - 1) {
      cout << " ";
    } else {
      cout << "\n";
    }
  }
  return 0;
}
