#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, w, t, z, k = 1, f[300500], a[300500], ans[300500];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  f[0] = f[m] = 1;
  for (int j = 0; j < 37; ++j)
    for (int i = 1; i < 1 << n; ++i) {
      x = a[k - 1] ^ i;
      y = x ^ m;
      if (!f[x] && !f[y]) f[x] = 1, ans[k] = i, a[k++] = x;
    }
  cout << k - 1 << endl;
  for (int i = 1; i < k; ++i) cout << ans[i] << " ";
}
