#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
constexpr int MAXN = 18;
bool was[1 << MAXN];
vector<int> pref;
int ans[1 << MAXN];
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, x;
  cin >> n >> x;
  was[0] = was[x] = true;
  for (int i = 0; i < (1 << n); ++i) {
    if (was[i]) {
      continue;
    }
    was[i ^ x] = true;
    pref.push_back(i);
  }
  reverse(std::begin(pref), std::end(pref));
  for (int i = static_cast<int>((pref).size()) - 1, pre = 0; i >= 0; --i) {
    ans[i] = pref[i] ^ pre;
    pre = pref[i];
  }
  cout << static_cast<int>((pref).size()) << "\n";
  outarr(ans, ans + static_cast<int>((pref).size()));
  return 0;
}
