#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int a[maxn];
map<int, int> M;
int vis[maxn];
int main() {
  int n, m, T, x;
  cin >> n >> x;
  int temp = (1 << n);
  if (n == 1 && x == 1) {
    cout << 0 << endl;
    return 0;
  }
  int s = 1;
  int p = 0, cnt = 0;
  while (1) {
    while (s == x || vis[s]) s++;
    if (s >= temp) break;
    a[++cnt] = (p ^ s);
    p ^= a[cnt];
    vis[(p ^ x)] = 1;
    vis[p] = 1;
    s++;
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
