#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  unordered_set<int> st;
  cin >> n >> x;
  for (int i = 1; i < (1 << n); ++i) {
    if (st.count(x ^ i) || i == x) {
      continue;
    }
    st.insert(i);
  }
  vector<int> v(st.begin(), st.end());
  cout << v.size() << "\n";
  int prev = 0;
  for (int i = 0; i < v.size(); ++i) {
    cout << (v[i] ^ prev) << " ";
    prev = v[i];
  }
  return 0;
}
