#include <bits/stdc++.h>
using namespace std;
long long ara[1000000], ans[1000000];
int main() {
  long long n, x, i, j;
  bool fg;
  cin >> n >> x;
  n = 1LL << n;
  ara[x] = ara[0] = 1;
  for (i = 1, j = 0; i < n; i++) {
    if (!ara[i]) {
      ans[++j] = i;
      ara[i] = ara[i ^ x] = 1;
    }
  }
  cout << j << endl;
  for (i = 1; i <= j; i++) printf("%lld ", ans[i] ^ ans[i - 1]);
  printf("\n");
  return 0;
}
