#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
int n, x;
vector<int> vec;
bool vis[300000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  int UB = 1 << n;
  for (int i = 1; i < UB; i++) {
    if (i == x) continue;
    if (vis[i]) continue;
    if (vis[i ^ x]) continue;
    vec.push_back(i);
    vis[i] = true;
    vis[i ^ x] = true;
  }
  cout << vec.size() << "\n";
  if (vec.size()) cout << vec[0] << " ";
  for (int i = 1; i < (int)vec.size(); i++) {
    int tmp = vec[i - 1] ^ vec[i];
    cout << tmp << " ";
  }
  return 0;
}
