#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long int powermod(long long int x, unsigned long long int y,
                       long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, x;
  cin >> n >> x;
  set<long long int> s;
  vector<long long int> pref, ans;
  for (long long int i = (long long int)(1); i < (long long int)((1ll << n));
       i++) {
    long long int xor0 = i, xorx = (x ^ i);
    if (s.find(xor0) != s.end() or s.find(xorx) != s.end() or i == x) continue;
    pref.push_back(i);
    s.insert(i);
  }
  if (pref.size()) ans.push_back(pref[0]);
  for (long long int i = (long long int)(1); i < (long long int)(pref.size());
       i++)
    ans.push_back(pref[i] ^ pref[i - 1]);
  cout << ans.size() << "\n";
  for (const auto itr : ans) {
    cout << itr << ' ';
  }
  cout << "\n";
  ;
  return 0;
}
