#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int limit = (1 << n);
  int i;
  vector<int> a, b;
  unordered_set<int> s;
  for (i = 1; i < limit; ++i) {
    if (i == x) continue;
    s.insert(i);
  }
  int c = 0;
  while (!s.empty()) {
    int temp = *(s.begin());
    b.push_back(temp);
    s.erase(temp);
    if (x < limit) {
      s.erase(x ^ temp);
    }
  }
  i = 0;
  for (i = 0; i < b.size(); ++i) {
    a.push_back(i == 0 ? b[i] : b[i - 1] ^ b[i]);
  }
  cout << a.size() << endl;
  for (i = 0; i < a.size(); ++i) {
    cout << a[i] << " ";
  }
  return 0;
}
