#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  return getchar();
  char buf[100000], *l = buf, *r = buf;
  return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)
             ? EOF
             : *l++;
}
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = nc();
  }
  x *= f;
}
const int maxn = (1 << 18) + 5;
int n, x, a[maxn];
bool mark[maxn];
void sol() {
  mark[0] = mark[x] = 1;
  int k = 1, s = 0, l;
  for (l = 1;; ++l) {
    while (mark[k]) ++k;
    if (k >= n) break;
    a[l] = s ^ k;
    s = k;
    mark[s] = mark[s ^ x] = 1;
  }
  --l;
  printf("%d\n", l);
  if (l) {
    for (int i = 1; i <= l; ++i) {
      if (i != 1) printf(" ");
      printf("%d", a[i]);
    }
    printf("\n");
  }
}
int main() {
  read(n), read(x), n = 1 << n;
  sol();
  return 0;
}
