#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long seens[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> x;
  vector<long long> A;
  vector<long long> B;
  seens[0] = 1;
  for (long long i = 1; i < (1LL << n); i++) {
    if (i == x) {
      seens[x] = 1;
      seens[0] = 1;
      continue;
    }
    long long anti = i ^ x;
    if (seens[anti] || seens[i]) continue;
    seens[anti] = 1;
    seens[i] = 1;
    A.push_back(i);
    if (anti < (1LL << n)) B.push_back(anti);
  }
  cout << A.size() << endl;
  if (A.size() == 0) {
    return 0;
  }
  cout << A[0] << " ";
  long long cur = A[0];
  for (long long i = 1; i < A.size(); i++) {
    cout << (A[i] ^ cur) << " ";
    cur = A[i];
  }
  cout << "\n";
  return 0;
}
