#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9 + 7;
const int nax = 1010100;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  int m = (1 << n);
  vector<bool> done(nax);
  vector<int> res;
  int cur = 0;
  done[0] = true;
  for (;;) {
    int comp = true;
    for (int i = (0); i < (n); i++) {
      int j = (1 << i);
      if (done[cur ^ j]) continue;
      if (done[cur ^ j ^ x]) continue;
      res.push_back(j);
      cur ^= j;
      done[cur] = 1;
      comp = false;
      break;
    }
    if (comp) break;
  }
  if (x >= m) {
    assert(res.size() == m - 1);
  } else {
    assert(res.size() == (m / 2 - 1));
  }
  cout << res.size() << '\n';
  for (auto x : res) cout << x << " ";
  return 0;
}
