#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;
int n, x, a[MAXN * 10];
bool f[MAXN * 10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> x;
  if (n == 1) {
    if (x == 1)
      cout << 0;
    else
      cout << "1\n1";
    return 0;
  }
  int N = 1;
  if (x == 1)
    a[1] = 2;
  else
    a[1] = 1;
  while (1) {
    for (int i = (1); i <= ((1 << n) - 1); i++) f[i] = true;
    f[x] = false;
    int g = 0;
    for (int i = (N); i >= (1); i--) {
      g = g ^ a[i];
      f[g] = false;
      int h = g ^ x;
      f[h] = false;
    }
    int vt = 0;
    for (int i = (1); i <= ((1 << n) - 1); i++)
      if (f[i] == true) {
        vt = i;
        break;
      }
    if (!vt) break;
    a[++N] = vt;
    N = N * 2 - 1;
    for (int i = (1); i <= (N / 2 + 1); i++) a[N - i + 1] = a[i];
  }
  cout << N << "\n";
  for (int i = (1); i <= (N); i++) cout << a[i] << ' ';
  return 0;
}
