#include <bits/stdc++.h>
using namespace std;
int n, x, dd[270000];
int main() {
  cin >> n >> x;
  int limit = (1 << n) - 1;
  vector<int> Q;
  Q.push_back(0);
  for (int i = 1; i <= limit; i++) {
    if (i == x) continue;
    if (dd[i]) continue;
    Q.push_back(i);
    dd[(i ^ x)] = 1;
  }
  cout << Q.size() - 1 << endl;
  for (int i = 1; i < Q.size(); i++) {
    cout << (Q[i] ^ Q[i - 1]) << " ";
  }
}
