#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 19;
int a[maxn], n, x;
int vis[maxn];
int cnt;
int main() {
  cin >> n >> x;
  if (x >= (1 << n)) {
    cnt = (1 << n) - 1;
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) a[i] = i;
    for (int i = 1; i <= cnt; i++) printf("%d ", a[i] ^ a[i - 1]);
  } else {
    vis[x] = 1;
    for (int i = 1; i < (1 << n); i++) {
      if (vis[i]) continue;
      a[++cnt] = i;
      vis[i ^ x] = 1;
      vis[i] = 1;
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d ", a[i] ^ a[i - 1]);
  }
}
