#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e16;
int LIM = 1e5 + 10;
vector<vector<long long int> > adj(LIM);
string s;
set<int> possible;
bool present(int value) { return possible.find(value) != possible.end(); }
void era(int temp) {
  auto it = possible.find(temp);
  possible.erase(it);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  for (int i = 1; i < (1 << n); i++) possible.insert(i);
  if (present(x)) {
    auto it = possible.find(x);
    possible.erase(it);
  }
  vector<long long int> arr;
  arr.push_back(0);
  while (possible.size() > 0) {
    auto it = possible.begin();
    int a = *it;
    arr.push_back(a);
    int b = a ^ x;
    if (present(a)) era(a);
    if (present(b)) era(b);
  }
  vector<long long int> ans;
  for (int i = 1; i < arr.size(); i++) {
    ans.push_back(arr[i] ^ arr[i - 1]);
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
