#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
int n, x, a[maxn], tp;
int main() {
  int i, j;
  cin >> n >> x;
  for (i = 1; i < (1 << n); i++)
    if ((i ^ x) >= i) a[++tp] = i;
  cout << tp << "\n";
  for (i = 1; i <= tp; i++) printf("%d ", a[i] ^ a[i - 1]);
  cout << "\n";
  return 0;
}
