#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
long long n, x, mark[N];
vector<long long> ans;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x;
  mark[x] = 1;
  for (int i = 1; i < (1 << n); i++) {
    if (mark[i] == 0) {
      mark[i] = 1;
      mark[x ^ i] = 1;
      ans.push_back(i);
    }
  }
  cout << ans.size() << endl;
  if (ans.size() > 0) cout << ans[0] << " ";
  for (int i = 1; i < ans.size(); i++) {
    long long z = ans[i] ^ ans[i - 1];
    cout << z << " ";
  }
  return 0;
}
