#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ;
  long long n, x;
  cin >> n >> x;
  map<long long, long long> f;
  vector<long long> pref;
  pref.push_back(0);
  f[0] = 1;
  for (long long i = 1; i < (1LL << n); i++) {
    if (f[i ^ x] == 0) {
      pref.push_back(i);
      f[i] = 1;
    }
  }
  cout << (long long)(pref).size() - 1 << "\n";
  for (long long i = 0; i + 1 < (long long)(pref).size(); i++) {
    cout << (long long)(pref[i] ^ pref[i + 1]) << " ";
  }
}
