#include <bits/stdc++.h>
using namespace std;
int p[300010];
int vis[300010];
vector<int> ans;
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < (1 << n); i++) {
    if (vis[i]) continue;
    p[i] = x ^ i;
    if (vis[p[i]]) continue;
    vis[p[i]] = 1;
    ans.push_back(i);
  }
  printf("%d\n", (int)ans.size() - 1);
  for (int i = 1; i < ans.size(); i++) {
    printf("%d ", ans[i] ^ ans[i - 1]);
  }
  printf("\n");
  return 0;
}
