#include <bits/stdc++.h>
using namespace std;
const long long N = (1 << 18) + 10;
struct sc {
  int l, r;
  bool operator<(const sc &a) const { return a.r > r || (a.r == r && a.l > l); }
} p[N];
int vis[N], n, k;
vector<int> ve;
int main() {
  scanf("%d %d", &n, &k);
  vis[k]++;
  int sum = 0;
  for (int i = 1; i < (1 << n); i++) {
    if (!vis[i]) {
      vis[i ^ k]++;
      ve.push_back(i);
    }
  }
  cout << ve.size() << endl;
  sum = 0;
  for (int i : ve) {
    cout << (i ^ sum) << ' ';
    sum = i;
  }
}
