#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int ans[1 << 19];
bool v[1 << 19];
int main() {
  int n, m, tot = 0;
  scanf("%d%d", &n, &m);
  v[m] = 1;
  int pre = 0;
  for (int i = 1; i < (1 << n); i++) {
    if (v[i]) continue;
    ans[++tot] = i ^ pre;
    pre = i;
    v[i] = 1;
    v[m ^ i] = 1;
  }
  printf("%d\n", tot);
  for (int i = 1; i <= tot; i++) printf("%d ", ans[i]);
}
