#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 18);
long long n, x, t;
bool mark[maxn + 10], ok;
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  mark[0] = true;
  mark[x] = true;
  while (1) {
    for (int i = 1; i < (1 << n); i++) {
      ok = false;
      if (!mark[t ^ i]) {
        v.push_back(i);
        t ^= i;
        mark[t] = true;
        mark[t ^ x] = true;
        ok = true;
        break;
      }
    }
    if (!ok) break;
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
