#include <bits/stdc++.h>
using namespace std;
long long fp[100005];
int main() {
  long long m, i, j, k1, k2, t, x, y, n, k, ans;
  cin >> n >> x;
  long long c[(1 << 18) + 1];
  vector<long long> v;
  v.push_back(0);
  memset(c, 0, sizeof(c));
  c[0] = 1;
  c[x] = 1;
  for (i = 1; i < (1 << n); i++) {
    if (c[i] == 0) {
      v.push_back(i);
      c[i] = 1;
      c[i ^ x] = 1;
    }
  }
  vector<long long> v2;
  for (i = 1; i < v.size(); i++) {
    v2.push_back(v[i] ^ v[i - 1]);
  }
  cout << v2.size() << '\n';
  for (i = 0; i < v2.size(); i++) {
    cout << v2[i] << " ";
  }
  cout << '\n';
  return 0;
}
