#include <bits/stdc++.h>
int n, x, a[1100000], bm, at;
bool b[1100000];
int main() {
  scanf("%d%d", &n, &x);
  bm = (1 << n) - 1;
  b[0] = 1;
  b[x] = 1;
  for (int i = 1; i <= bm; i++)
    if (!b[i] && !b[i ^ x]) {
      a[++at] = i;
      b[i] = 1;
      b[i ^ x] = 1;
    }
  for (int i = at; i >= 2; i--) a[i] ^= a[i - 1];
  printf("%d\n", at);
  for (int i = 1; i <= at; i++) printf("%d ", a[i]);
  return 0;
}
