#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = (1e18);
const ll mod = 1000000007;
const ll mod2 = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, x;
  cin >> n >> x;
  vector<ll> b;
  set<int> s;
  s.insert(0);
  for (int i = 0; i < (1 << n); i++) {
    if (s.find(i) != s.end() || s.find(i ^ x) != s.end()) continue;
    b.push_back(i);
    s.insert(i);
  }
  cout << b.size() << endl;
  if (b.size()) {
    cout << b[0] << " ";
    for (int i = 1; i < b.size(); i++) {
      cout << (b[i - 1] ^ b[i]) << " ";
    }
    cout << endl;
  }
}
