#include <bits/stdc++.h>
using namespace std;
bool vis[1 << 20];
void solve() {
  int n, x;
  scanf("%d%d", &n, &x);
  vis[0] = vis[x] = 1;
  int pre = 0;
  printf("%d\n", (x < (1 << n)) ? (1 << (n - 1)) - 1 : (1 << n) - 1);
  for (int i = 1; i < (1 << n); i++) {
    if (!vis[i]) {
      printf("%d ", i ^ pre);
      vis[i ^ x] = 1;
      pre = i;
    }
  }
}
int main() {
  solve();
  return 0;
}
