#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
vector<long long int> v, v1;
map<long long int, long long int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, x;
  cin >> n >> x;
  m[x] = 1;
  for (long long int i = (1 << n) - 1; i > 0; i--) {
    if (m[i] == 0) {
      v.push_back(i);
      m[i] = 1;
      m[i ^ x] = 1;
    }
  }
  if (n == 1 and x == 1) {
    cout << 0 << endl;
    return 0;
  }
  cout << v.size() << endl;
  cout << v[0] << " ";
  for (long long int i = 1; i < v.size(); i++) {
    cout << (v[i] ^ v[i - 1]) << " ";
  }
}
