#include <bits/stdc++.h>
using namespace std;
const int sz = 362144;
int vis[sz], ans[sz];
void solve() {
  long long int n, x, i, j = 0;
  cin >> n >> x;
  for (i = 0; i < (1 << n); i++) {
    if (!vis[i]) {
      ans[j++] = i;
      vis[i ^ x] = 1;
    }
  }
  cout << j - 1 << endl;
  for (i = 1; i < j; i++) {
    cout << (ans[i] ^ ans[i - 1]) << ' ';
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
