#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
int main() {
  int n, x;
  cin >> n >> x;
  int m = 1;
  int a[1001000];
  int p[1001000];
  p[0] = 1;
  p[x] = 1;
  for (int i = 0; i < (1 << n); i++) {
    if (!p[i]) {
      a[m++] = i;
      p[i] = 1;
      p[i ^ x] = 1;
    }
  }
  cout << m - 1 << '\n';
  for (int i = 1; i < m; i++) {
    cout << (a[i] ^ a[i - 1]) << " ";
  }
  return 0;
}
