#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
void solve(int n, int onBit) {
  if (n == 0) return;
  solve(n - 1, onBit);
  int num = (n - 1) < onBit ? (1 << (n - 1)) : (1 << n);
  ans.push_back(num);
  solve(n - 1, onBit);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int bits, x;
  cin >> bits >> x;
  if (x >> bits) {
    solve(bits, bits);
  } else {
    int onBit;
    for (int i = 0;; ++i)
      if ((x >> i) & 1) {
        onBit = i;
        break;
      }
    solve(bits - 1, onBit);
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << ' ';
  cout << '\n';
}
