#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x;
  set<long long> st;
  vector<long long> v;
  st.insert(0);
  for (long long i = (1 << n) - 1; i > 0; i--) {
    if (!st.count(i ^ x)) {
      st.insert(i);
      v.emplace_back(i);
    }
  }
  int m = v.size();
  vector<long long> a(m);
  for (int i = 0; i < m; i++) {
    if (!i)
      a[i] = v[i];
    else
      a[i] = v[i] ^ v[i - 1];
  }
  cout << m << endl;
  if (m) {
    for (auto e : a) cout << e << " ";
    cout << endl;
  }
  return 0;
}
