#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v1;
long long int n, m, i, j, k, l, t, a, b, c, d;
int main() {
  scanf("%lld %lld", &n, &k);
  m = n;
  t = 1;
  l = n;
  while (m) {
    t *= 2;
    m--;
  }
  if (t > k) l--;
  b = t / 2;
  t = 1;
  for (i = 0; i < l; i++) {
    for (j = 0; j < v.size(); j++) v1.push_back(v[j]);
    v1.push_back(t);
    for (j = 0; j < v.size(); j++) v1.push_back(v[j]);
    v.clear();
    for (j = 0; j < v1.size(); j++) v.push_back(v1[j]);
    v1.clear();
    t *= 2;
  }
  a = 1;
  while (l--) a *= 2;
  while (a) {
    if (k >= a) {
      t = a;
      break;
    }
    a /= 2;
  }
  for (i = 0; i < v.size(); i++) {
    if (v[i] == t) v[i] = b;
  }
  printf("%d\n", v.size());
  for (i = 0; i < v.size(); i++) printf("%lld ", v[i]);
}
