#include <bits/stdc++.h>
using namespace std;
vector<int> v;
set<int> s;
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  int bound = 1 << n;
  for (int i = 1; i < bound; i++) s.insert(i);
  v.push_back(0);
  while (!s.empty()) {
    int tmp = *s.begin();
    if (x < bound) {
      if (tmp == x)
        s.erase(tmp);
      else {
        v.push_back(tmp);
        s.erase(tmp);
        s.erase(tmp ^ x);
      }
    } else {
      v.push_back(tmp);
      s.erase(tmp);
    }
  }
  if (v.size() == 1) {
    printf("0");
  } else {
    printf("%d\n", v.size() - 1);
  }
  for (int i = 0; i < v.size() - 1; i++) {
    printf("%d ", v[i] ^ v[i + 1]);
  }
}
