#include <bits/stdc++.h>
using namespace std;
const int MX = (int)5e5 + 10;
const int mod = 998244353;
int main(int argc, char* argv[]) {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, x;
  cin >> n >> x;
  int mx = 1 << n;
  vector<int> a;
  int popo = 0;
  map<int, int> mp;
  for (int i = 0; i < mx; ++i) {
    for (int j = 1; j < mx; j *= 2) {
      if (j == x) continue;
      int pref = popo ^ j;
      if (pref == 0 || pref == x) continue;
      if (!mp.count(pref ^ x) && !mp.count(pref)) {
        mp[pref]++;
        a.push_back(j);
        popo ^= j;
        break;
      }
    }
    if ((int)a.size() != i + 1) break;
  }
  cout << a.size() << endl;
  for (auto& z : a) cout << z << " ";
  cout << endl;
  return 0;
}
