#include <bits/stdc++.h>
using namespace std;
int vis[300000];
vector<int> ans;
int main() {
  int n, m, nn, i;
  cin >> nn >> m;
  ans.push_back(0);
  vis[0] = 1;
  vis[m] = 1;
  for (i = 0; i < (1 << nn); i++) {
    if (!vis[i]) {
      ans.push_back(i);
      vis[i ^ m] = 1;
    }
  }
  cout << ans.size() - 1 << endl;
  for (int i = 1; i < ans.size(); i++) {
    int xx;
    xx = ans[i - 1] ^ ans[i];
    cout << xx << " ";
  }
  return 0;
}
