#include <bits/stdc++.h>
using namespace std;
int isp[100005];
int main() {
  long long int n, x;
  int flag = 0;
  cin >> n >> x;
  long long int m = 1LL << n;
  if (x >= m) flag = 1;
  int vis[1000000];
  memset(vis, 0, sizeof(vis));
  vector<long long int> a;
  for (int i = 0; i < m; i++) {
    if (!vis[i]) {
      a.push_back(i);
      if (flag == 0) {
        vis[i] = 1;
        vis[(i ^ x)] = 1;
      }
    }
  }
  cout << a.size() - 1 << endl;
  for (int i = 0; i < a.size() - 1; i++) cout << (a[i] ^ a[i + 1]) << " ";
  return 0;
}
