#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5, inf = 1e18;
long long n, x;
vector<long long> vec;
bool mark[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> x;
  mark[0] = mark[x] = true;
  for (long long i = 0; i < (1ll << n); i++) {
    if (mark[i] != true) {
      vec.push_back(i);
      mark[i] = true;
      mark[(i ^ x)] = true;
    }
  }
  cout << vec.size() << endl;
  long long px = 0;
  for (auto X : vec) {
    cout << (X ^ px) << " ";
    px = X;
  }
  return 0;
}
