#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
bool a[N];
vector<int> res;
int x, n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> x;
  res.push_back(0);
  a[0] = true;
  for (int i = 1; i <= int((1 << n) - 1); i++) {
    if (a[i ^ x]) continue;
    res.push_back(i);
    a[i] = true;
  }
  cout << res.size() - 1 << "\n";
  for (int i = 1; i <= int(res.size() - 1); i++) {
    int t = res[i] ^ res[i - 1];
    cout << t << " ";
  }
  return 0;
}
