#include <bits/stdc++.h>
using namespace std;
int a[500000];
int sum;
int main() {
  int n, k;
  cin >> n >> k;
  n = 1 << n;
  cout << ((n >> (k < n)) - 1) << endl;
  for (int i = 1; i < n; i++)
    if (i < (i ^ k)) cout << (sum ^ i) << " ", sum = i;
  return 0;
}
