#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, i, m;
  scanf("%d%d", &n, &x);
  int prev = 0;
  if (x >= (1 << n)) {
    printf("%d\n", (1 << n) - 1);
    for (i = 0; i < (1 << n) - 1; ++i) printf("%d ", i ^ (i + 1));
    return 0;
  }
  printf("%d\n", (1 << (n - 1)) - 1);
  for (m = 0; m < 1 << n; ++m) {
    if (m == 0 || m == x) continue;
    if ((m ^ x) > m) {
      printf("%d ", prev ^ m);
      prev = m;
    }
  }
}
