#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 18);
int a[maxn + 5];
vector<int> p;
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 1; i < (1 << n); i++) {
    int t = x ^ i;
    if (i == x || t == x) continue;
    if (i >= t) continue;
    p.push_back(i);
  }
  cout << p.size() << "\n";
  int last = 0;
  for (int i = 0; i < p.size(); i++) {
    cout << (p[i] ^ last) << " ";
    last = p[i];
  }
  return 0;
}
