#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge {
  ll from;
  ll to;
  ll cost;
};
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> s;
  bitset<(1 << 18)> used;
  for (ll i = 0; i < 1 << n; ++i) {
    if (used[i]) continue;
    s.push_back(i);
    used[i] = used[i ^ x] = 1;
  }
  int sz = s.size() - 1;
  cout << sz << endl;
  for (ll i = 0; i < sz; ++i) {
    printf("%d", s[i] ^ s[i + 1]);
    printf(i == sz - 1 ? "\n" : " ");
  }
  return 0;
}
