#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const long long N = 5e5;
long long pref[N];
bool vis[N];
void solve() {
  long long n, x;
  cin >> n >> x;
  long long idx = 1;
  for (long long i = 1; i < 1 << n; ++i) {
    if (!vis[i] and !vis[i ^ x] and i != x) {
      pref[idx++] = i;
      vis[i] = true;
    }
  }
  cout << idx - 1 << '\n';
  for (long long i = 1; i < idx; ++i) {
    cout << (pref[i] ^ pref[i - 1]) << ' ';
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
