#include <bits/stdc++.h>
using namespace std;
const int n = (1 << 18) + 5;
int N, X;
int A[n], P[n];
int main() {
  cin >> N >> X;
  int T = 0;
  int i;
  int Xab = 1 << ((int)log2(X));
  int rz = 1;
  for (int z = 1; z < (1 << N) + 1; z *= 2) {
    if (z == Xab) {
      rz *= 2;
    }
    for (int i = 0; i < (1 << N) + 1; i += z) {
      A[i] = rz;
    }
    rz *= 2;
  }
  int Z = 1 << N;
  if (X < (1 << N)) {
    Z = 1 << (N - 1);
  }
  Z--;
  cout << Z << endl;
  for (int i = 1; i <= Z; ++i) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}
