#include <bits/stdc++.h>
using namespace std;
long long findb(long long b[], long long i, long long r) {
  long long ret = upper_bound(b, b + r, i) - b;
  if (ret == r)
    return -1;
  else
    return b[ret];
}
long long c2(long long k) { return (k * (k - 1) / 2); }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long ans = 1;
void power(long long x, long long y, long long p) {
  long long ret = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ret = (ret * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  ans = ret * ans;
  ans = ans % 1000000007;
}
vector<long long> v;
void primeFactors(long long n) {
  if (n % 2 == 0) {
    v.push_back(2);
    while (n % 2 == 0) n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    if (n % i == 0) {
      v.push_back(i);
      while (n % i == 0) n = n / i;
    }
  }
  if (n > 2) v.push_back(n);
}
long long PowerOFPINnfactorial(long long n, long long p) {
  long long answ = 0;
  while (n > 0) {
    answ += n / p;
    n = n / p;
  }
  return answ;
}
int32_t main() {
  long long n, x;
  cin >> n >> x;
  long long k = 1 << n;
  if (x >= k) {
    long long b[k - 1];
    for (long long i = 1; i < k; i++) b[i - 1] = i;
    long long a[k];
    a[0] = b[0];
    for (long long i = 1; i < k - 1; i++) a[i] = b[i] ^ b[i - 1];
    cout << k - 1 << endl;
    for (long long i = 0; i < k - 1; i++) cout << a[i] << " ";
  } else {
    long long hoga[k];
    for (long long i = 0; i < k; i++) hoga[i] = -1;
    hoga[0] = 0;
    hoga[x] = 0;
    for (long long i = 0; i < k; i++) {
      long long p = i ^ x;
      if (hoga[i] == -1) hoga[i] = 0;
      if (hoga[p] == -1) hoga[p] = 1;
    }
    long long count = 0;
    for (long long i = 1; i < k; i++)
      if (hoga[i] == 1) count++;
    cout << count << endl;
    long long b[count];
    long long j = 0;
    for (long long i = 1; i < k; i++)
      if (hoga[i] == 1) b[j++] = i;
    long long a[count];
    a[0] = b[0];
    for (long long i = 1; i < count; i++) a[i] = b[i] ^ b[i - 1];
    for (long long i = 0; i < count; i++) cout << a[i] << " ";
  }
}
