#include <bits/stdc++.h>
using namespace std;
long long int dp[100000] = {0};
bool a[(1 << 18)];
int main() {
  long long int n, x;
  cin >> n >> x;
  vector<long long int> v;
  a[0] = 1;
  v.push_back(0);
  for (long long int i = 1; i < (1 << n); i++) {
    if (a[i ^ x]) {
      continue;
    }
    v.push_back(i);
    a[i] = 1;
  }
  cout << v.size() - 1 << "\n";
  for (long long int i = 1; i < v.size(); i++) {
    cout << (v[i] ^ v[i - 1]) << " ";
  }
}
