#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
constexpr int N = 1e5 + 5;
int n, x, l = 0;
set<int> ans;
void Solve() {
  cin >> n >> x;
  for (int i = 1; i < (1 << n); i++) {
    if (ans.find(i ^ x) == ans.end()) ans.insert(i);
  }
  ans.erase(x);
  cout << ans.size() << "\n";
  for (int el : ans) {
    if (l == 0)
      cout << el << " ";
    else
      cout << (el ^ l) << " ";
    l = el;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  Solve();
  return 0;
}
