#include <bits/stdc++.h>
using namespace std;
bool bxor[(1 << 18)];
int main() {
  long long int n, x;
  cin >> n >> x;
  vector<long long int> v;
  v.push_back(0);
  bxor[0] = bxor[x] = 1;
  for (int i = 1; i < (1 << n); i++) {
    if (bxor[i]) continue;
    v.push_back(i);
    bxor[i] = bxor[i ^ x] = 1;
  }
  cout << v.size() - 1 << endl;
  for (size_t i = 1; i <= v.size() - 1; i++) {
    cout << (v[i] ^ v[i - 1]) << ' ';
  }
  return 0;
}
