#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = LONG_LONG_MAX;
set<int> s;
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  n = (1 << n);
  vector<int> v;
  for (int i = 1; i < n; i++) {
    if (i == x) continue;
    if (s.find(i) == s.end()) v.push_back(i);
    s.insert(i ^ x);
  }
  int sz = (int)v.size();
  printf("%d\n", sz);
  if (sz == 0) return 0;
  printf("%d ", v[0]);
  for (int i = 0; i < sz - 1; i++) printf("%d ", v[i] ^ v[i + 1]);
  return 0;
}
