#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void need_for_speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool vis[10000000];
int32_t main() {
  need_for_speed();
  long long n, x;
  cin >> n >> x;
  vis[0] = 1;
  vector<long long> v({0});
  for (long long i = 1; i < (1 << n); i++) {
    if (vis[i ^ x]) continue;
    vis[i] = 1;
    v.push_back(i);
  }
  cout << v.size() - 1 << "\n";
  vector<long long> ans;
  for (long long i = 1; i < v.size(); i++) {
    ans.push_back(v[i] ^ v[i - 1]);
  }
  for (auto i : ans) cout << i << " ";
  cout << "\n";
  return 0;
}
