#include <bits/stdc++.h>
using namespace std;
long long n, k, sz;
vector<bool> cand;
void init();
void process();
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  process();
  cout.flush();
  return 0;
}
void init() {
  cin >> n >> k;
  sz = 1 << n;
  cand.resize(1 << n, true);
  cand[0] = false;
  if (k < sz) cand[k] = false;
}
map<long long, long long> mp;
long long foo(long long n) {
  if (n == 0) return 1;
  if (mp.count(n) != 0)
    return mp[n];
  else
    return mp[n] = 1 + 2 * foo(n - 1);
}
void print(long long i, long long n, vector<long long> &ans) {
  if (i == 0) {
    cout << ans[0] << " ";
    return;
  }
  print(i - 1, n, ans);
  cout << ans[i] << " ";
  print(i - 1, n, ans);
}
void process() {
  vector<long long> ans;
  vector<long long> fix;
  long long cidx = 1;
  while (cidx < cand.size()) {
    if (cand[cidx] == false) {
      cidx++;
      continue;
    }
    ans.push_back(cidx);
    fix.insert(fix.end(), fix.begin(), fix.end());
    for (size_t i = fix.size() / 2; i < fix.size(); i++) {
      fix[i] ^= cidx;
      if (fix[i] < sz) cand[fix[i]] = false;
      if ((fix[i] ^ k) < sz) cand[fix[i] ^ k] = false;
    }
    fix.push_back(cidx);
    cand[cidx] = false;
    if ((cidx ^ k) < sz) cand[cidx ^ k] = false;
    cidx++;
  }
  if (ans.size() == 0)
    cout << 0 << '\n';
  else {
    long long anssz = foo(ans.size() - 1);
    cout << anssz << '\n';
    if (anssz != 0) {
      print(ans.size() - 1, ans.size(), ans);
    }
    cout << '\n';
  }
}
