#include <bits/stdc++.h>
using namespace std;
int vis[(1 << 18)];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  vis[0] = 1;
  vector<int> pref({0});
  for (int i = 1; i < (1 << n); ++i) {
    if (vis[i ^ x]) continue;
    pref.push_back(i);
    vis[i] = 1;
  }
  int siz = pref.size();
  printf("%d\n", siz - 1);
  for (int i = 1; i < siz; ++i) printf("%d ", (pref[i] ^ pref[i - 1]));
  printf("\n");
  return 0;
}
