#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int n, x, freq;
vector<int> powers, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  for (int i = 0; i <= 18; i++) powers.push_back((1 << i));
  if (x >= floor(pow(2, n)))
    freq = floor(pow(2, n)) - 1;
  else
    freq = floor(pow(2, n - 1)) - 1;
  int p = 1;
  while (p <= x) p *= 2;
  p /= 2;
  cout << freq << '\n';
  int j = 0;
  bool space = 0, inc;
  while (ans.size() < freq) {
    if (space)
      cout << " ";
    else
      space = 1;
    inc = 0;
    if (powers[j] >= p) {
      j++;
      inc = 1;
    }
    cout << powers[j];
    ans.push_back(powers[j]);
    if (!inc) j++;
    int sz = ans.size() - 1;
    for (int j = 0; j < sz; j++) {
      cout << " " << ans[j];
      ans.push_back(ans[j]);
    }
  }
  cout << '\n';
  return 0;
}
