#include <bits/stdc++.h>
const long long mod = (long long)1e9 + 7;
using namespace std;
long long change(long long x, long long b, long long n) {
  x = 2 * x;
  for (long long i = 0; i <= b; i++) {
    x = x & (~(1ll << i));
  }
  for (long long i = 0; i < b; i++) {
    if (n & (1ll << i)) {
      x = x | (1ll << i);
    }
  }
  return x;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n >> x;
  bool foo = false;
  if (x < (1ll << n)) {
    n--;
    foo = true;
  }
  vector<long long> vc;
  long long X = 1;
  while ((long long)vc.size() != ((1ll << n) - 1)) {
    vc.push_back(X);
    long long N = vc.size();
    for (long long i = 0; i < N - 1; i++) vc.push_back(vc[i]);
    X *= 2;
  }
  if (foo) {
    long long b = 0;
    for (long long i = 18; i >= 0; i--) {
      if (x & (1ll << i)) {
        b = i;
        break;
      }
    }
    for (long long i = 0; i < (long long)vc.size(); i++) {
      vc[i] = change(vc[i], b, vc[i]);
    }
  }
  cout << (long long)vc.size() << "\n";
  for (auto i : vc) cout << i << ' ';
  return 0;
}
