#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using PI = pair<int, int>;
using VPI = vector<PI>;
using VVPI = vector<VPI>;
using VL = vector<long long>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VC = vector<char>;
using VVC = vector<VC>;
mt19937_64 gen(chrono::system_clock::now().time_since_epoch().count());
int rd(int a, int b) { return uniform_int_distribution<int>(a, b)(gen); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  if (n == 1) {
    if (x == 1)
      cout << 0;
    else
      cout << 1 << '\n' << 1;
    return 0;
  }
  int m = pow(2, n);
  VI a(m);
  for (int i = 0; i < m; ++i) {
    int w = i + 1, licz = 1;
    while (w % 2 == 0) {
      w >>= 1;
      licz <<= 1;
    }
    a[i] = licz;
  }
  if (x >= m) {
    cout << m - 1 << '\n';
    for (int i = 0; i < m - 1; ++i) cout << a[i] << ' ';
  } else {
    for (int i = 0; i < m; ++i)
      if (a[i] * 2 > x) a[i] <<= 1;
    cout << m / 2 - 1 << '\n';
    for (int i = 0; i < m / 2 - 1; ++i) cout << a[i] << ' ';
  }
  return 0;
}
