#include <bits/stdc++.h>
using namespace std;
int n, x;
int vis[(1 << 18) + 5];
int main() {
  cin >> n >> x;
  for (int i = 0; i < 1 << n; i++) {
    if (!vis[i]) vis[i ^ x] = 1;
  }
  int lst = 0;
  vector<int> vec;
  for (int i = 1; i < 1 << n; i++) {
    if (!vis[i]) {
      vec.push_back(i ^ lst);
      lst = i;
    }
  }
  printf("%d\n", (int)vec.size());
  for (size_t i = 0; i < vec.size(); i++) printf("%d ", vec[i]);
  puts("");
}
