#include <bits/stdc++.h>
using namespace std;
void pv(vector<int> v) {
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i] << " ";
  }
  cout << "" << endl;
}
void pa(int a[], int n, int p) {
  for (int i = p; i < n + p; ++i) {
    cout << a[i] << " ";
  }
  cout << "" << endl;
}
const double pi = 3.141592653589793238;
const int inf = 1000000;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  std::vector<int> v, ans;
  for (int i = 1; i <= (1 << n) - 1; i += 1) {
    if ((i ^ x) > i) v.push_back(i);
  }
  if (v.size()) {
    ans.push_back(v[0]);
    int l = v.size();
    for (int i = 1; i <= l - 1; i += 1) ans.push_back(v[i] ^ v[i - 1]);
  }
  pv(ans);
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
