#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long inf = 1e18;
const int maxn = 1e5 + 10;
const double eps = 1e-7;
const double pi = 3.14159265359;
bool ex[(1 << 18)];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  scanf("%d%d", &n, &x);
  ex[0] = 1;
  vector<int> v({0});
  for (int i = 1; i < (1 << n); i++) {
    if (ex[i ^ x]) continue;
    v.push_back(i);
    ex[i] = 1;
  }
  printf("%d\n", v.size() - 1);
  for (int i = 1; i < v.size(); i++) {
    printf("%d ", (v[i] ^ v[i - 1]));
  }
}
