#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int cmod = 998244353;
const long long int N = 2e5 + 5;
const long long int inf = 1e16 + 2;
void solve(long long int ze) {
  long long int n, x, t, pr = 0;
  cin >> n >> x;
  vector<long long int> ans;
  map<long long int, long long int> check;
  check[0] = 1;
  check[x] = 1;
  for (long long int i = 1; i < (1LL << n); i++) {
    if (!check[i]) {
      ans.push_back(pr ^ i);
      pr = i;
      check[i] = 1;
      check[i ^ x] = 1;
    }
  }
  cout << ans.size() << '\n';
  for (auto x : ans) cout << x << ' ';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int testcase = 1;
  long long int x = 1;
  while (testcase--) {
    solve(x++);
  }
  return 0;
}
