#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 100;
int n, x, LOG[N];
bool have;
vector<int> vec;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  for (int i = 0; i <= 20; i++) LOG[1 << i] = i;
  cin >> n >> x;
  if (x >= (1 << n)) {
    for (int i = 0; i < n; i++) vec.push_back(1 << i);
    cout << (1 << vec.size()) - 1 << '\n';
    for (int i = 1; i < (1 << vec.size()); i++) cout << vec[LOG[i & -i]] << ' ';
    return 0;
  }
  vector<int> help = {0};
  for (int i = 1; i < (1 << n); i++)
    if ((i ^ x) > i) help.push_back(i);
  cout << help.size() - 1 << '\n';
  for (int i = 1; i < help.size(); i++) cout << (help[i] ^ help[i - 1]) << ' ';
  return 0;
}
