#include <bits/stdc++.h>
using namespace std;
int n, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> x;
  if (x >= (1 << n)) x = 0;
  int cur = x;
  int target = 1;
  int mx = (1 << n);
  vector<int> ans;
  set<int> usd;
  usd.insert(x);
  usd.insert(0);
  while (target < mx) {
    if (usd.count(target ^ x)) {
      ++target;
      continue;
    }
    int nxt = (cur ^ target);
    ans.push_back(nxt);
    usd.insert(target);
    cur ^= nxt;
    ++target;
  }
  int n1 = ans.size();
  cout << n1 << "\n";
  for (auto zkw : ans) cout << zkw << " ";
  cout << "\n";
  return 0;
}
