#include <bits/stdc++.h>
using namespace std;
void print_ans(vector<int> &ans) {
  cout << ans.size() << endl;
  for (auto x : ans) cout << x << " ";
  puts("");
}
int used[270000];
map<int, int> base;
int n, x;
vector<int> val;
int main() {
  cin >> n >> x;
  vector<int> ans;
  int prefixor = 0;
  for (int i = 1; i < (1 << n); i++) {
    if ((prefixor ^ i) == 0 or (prefixor ^ i) == x or i == x) continue;
    if (used[prefixor ^ i] or used[prefixor ^ i ^ x]) continue;
    ans.push_back(i);
    used[prefixor ^ i] = 1;
    prefixor ^= i;
    i = 0;
  }
  print_ans(ans);
}
