#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long power(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
void build() {}
bool prime[100001];
void SieveOfEratosthenes() {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 100001; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= 100001; i += p) prime[i] = false;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  build();
  long long n, x;
  cin >> n >> x;
  map<long long, long long> m;
  m[0] = 1;
  m[x] = 1;
  long long p = 0;
  vector<long long> ans;
  while (1) {
    bool f = 0;
    for (long long i = 1; i < (1 << n); i++) {
      long long xr = i ^ p;
      if (m[xr] == 0 && m[xr ^ x] == 0) {
        ans.push_back(i);
        p = xr;
        m[p] = 1;
        f = 1;
      }
    }
    if (!f) break;
  }
  cout << ans.size() << endl;
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  ;
  return 0;
}
