#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
vector<long long> v;
void solve() {
  long long n, x;
  cin >> n >> x;
  if (x >= (1 << n)) {
    long long len = (1 << n) - 1;
    v.push_back(1);
    long long cur = 1;
    while ((long long)v.size() < len) {
      cur = 2 * cur + 1;
      v.push_back(cur);
      long long idx = (long long)v.size() - 2;
      for (long long j = idx; j >= 0; --j) {
        v.push_back(v[j]);
      }
    }
  } else {
    long long len = (1 << (n - 1)) - 1;
    long long f = x;
    while (__builtin_popcount(f) != 1) {
      f -= f & -f;
    }
    f = 2 * f - 1;
    if (x == 1) f = (1 << n) - 1;
    if (len) v.push_back(1);
    long long cur = 1;
    while ((long long)v.size() < len) {
      cur = 2 * cur + 1;
      if (cur == f) continue;
      v.push_back(cur);
      long long idx = (long long)v.size() - 2;
      for (long long j = idx; j >= 0; --j) {
        v.push_back(v[j]);
      }
    }
    if (x == 1) {
      for (long long &i : v) i *= 2;
    }
  }
  cout << (long long)v.size() << '\n';
  for (long long i : v) {
    cout << i << ' ';
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
