#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  long long n, x, i;
  cin >> n >> x;
  vector<long long> pref;
  map<long long, long long> ma;
  pref.push_back(0);
  ma[0] = 1;
  for (i = 1; i < (1 << n); i++) {
    if (ma[i ^ x] == 1) continue;
    pref.push_back(i);
    ma[i] = 1;
  }
  cout << pref.size() - 1 << endl;
  for (i = 1; i < pref.size(); i++) {
    cout << (pref[i] ^ pref[i - 1]) << " ";
  }
}
