#include <bits/stdc++.h>
using namespace std;
bool xr[(1 << 18)];
int main() {
  int n, x;
  cin >> n >> x;
  int m = 1 << n;
  xr[0] = true;
  vector<int> a({0});
  for (int i = 1; i < m; i++) {
    int y = x ^ i;
    if (xr[y]) continue;
    xr[i] = true;
    a.push_back(i);
  }
  int l = a.size();
  cout << l - 1 << endl;
  for (int i = 1; i < l; i++) cout << (a[i] ^ a[i - 1]) << " ";
  return 0;
}
