#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
const long long inf = 0x7f7f7f7f;
const long long mod = 1e9 + 7;
double pi = acos(-1.0);
int b[(1 << 18) + 100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  b[0] = 0;
  if (x >= (1 << n)) {
    int k = 1;
    for (int i = 1; i < (1 << n); i++) b[k++] = i;
    cout << k - 1 << endl;
    for (int i = 1; i < k; i++) cout << (b[i - 1] ^ b[i]) << " ";
    cout << endl;
  } else {
    int k = 1;
    set<int> q;
    set<int>::iterator iter;
    for (int i = 1; i < (1 << n); i++) {
      iter = q.find((i ^ x));
      if (iter != q.end()) continue;
      if (i == x) continue;
      q.insert(i);
      b[k++] = i;
    }
    cout << k - 1 << endl;
    for (int i = 1; i < k; i++) cout << (b[i - 1] ^ b[i]) << " ";
    cout << endl;
  }
}
