#include <bits/stdc++.h>
using namespace std;
void coordinate_compress(long long a[], long long n) {
  long long b[n];
  for (long long i = 0; i < n; i++) b[i] = a[i];
  sort(b, b + n);
  for (long long i = 0; i < n; i++) {
    a[i] = lower_bound(b, b + n, a[i]) - b;
  }
}
const int maxn = 2e5;
vector<int> answer, an2;
int main() {
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  int temp = x;
  int ls = 0;
  while ((temp != 0)) {
    temp /= 2;
    ls++;
  }
  ls--;
  answer.push_back(0);
  an2.push_back(0);
  for (int i = 1; i < (1 << n); i++) {
    if (((i >> ls) & 1) != 1) {
      answer.push_back((*(an2.end() - 1) ^ i));
      an2.push_back(i);
    }
  }
  cout << answer.size() - 1 << endl;
  for (auto i : answer) {
    if (i != 0) cout << i << " ";
  }
}
