#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 18;
int a[maxn];
int ex[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  if (x >= (1 << n)) {
    vector<int> v;
    v.push_back(0);
    cout << (1 << n) - 1 << endl;
    for (int i = 1; i < (1 << n); i++) v.push_back(i);
    int sz = v.size();
    for (int i = 1; i < sz; i++) cout << (v[i] ^ v[i - 1]) << ' ';
    cout << endl;
    return 0;
  } else {
    vector<int> v;
    v.push_back(0);
    ex[0] = 1;
    for (int i = 1; i < (1 << n); i++)
      if (!ex[i ^ x]) {
        ex[i] = 1;
        v.push_back(i);
      }
    cout << v.size() - 1 << endl;
    int sz = v.size();
    for (int i = 1; i < sz; i++) cout << (v[i] ^ v[i - 1]) << ' ';
    cout << endl;
  }
}
