#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x;
  cin >> n >> x;
  std::vector<int> a;
  std::vector<int> p(1e6 + 20, 0);
  std::vector<int> xo;
  xo.push_back(0);
  p[x] = p[0] = 1;
  for (int pi = 1; pi < (1 << n); pi++) {
    if (p[pi]) continue;
    a.push_back(pi ^ xo.back());
    p[pi ^ x] = 1;
    p[pi] = 1;
    xo.push_back(pi);
  }
  cout << a.size() << endl;
  if (a.size() != 0) {
    for (int y : a) cout << y << " ";
    cout << endl;
  }
}
