#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e12;
int pow1(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long vis[1 << 18];
int main() {
  long long t = 1;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    vector<long long> v;
    long long lmt = 1 << n;
    vis[0] = 1;
    for (long long i = 1; i < lmt; i++) {
      if (vis[i ^ x] == 1) continue;
      v.push_back(i);
      vis[i] = 1;
    }
    cout << v.size();
    if (v.size() > 0) {
      cout << "\n";
      cout << v[0] << " ";
      for (long long i = 1; i < v.size(); i++) {
        long long tmp = v[i] ^ v[i - 1];
        cout << tmp << " ";
      }
    }
  }
}
