#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 5;
const double eps = 1e-4;
const int mod = 1e9 + 7;
int a[N];
int vis[N];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int cnt = 0;
  vis[x] = 1;
  int tep = 0;
  for (int i = 1; i < (1 << n); i++) {
    if (!vis[i]) {
      vis[i ^ x] = 1;
      a[++cnt] = tep ^ i;
      tep = i;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) {
    printf("%d", a[i]);
    if (i != cnt)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
