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