code:
#include <bits/stdc++.h>
#define N 1000000
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int vis[N],b[N];
void solve()
{
int n,m,i,j,cur=1,cnt=0;
memset(vis,0,sizeof(vis));
scanf("%d%d",&n,&m);
vis[m]=1;
for(i=1;i<=(1<<n);++i)
{
while(vis[cur]) ++cur;
if((cur^b[cnt-1]) >= (1<<n)) break;
b[++cnt]=cur;
vis[cur^m]=1;
++cur;
}
printf("%d\n",cnt);
for(i=0;i<cnt;++i) printf("%d ",b[i]^b[i+1]);
}
int main()
{
int i,j,T;
// setIO("input");
solve();
return 0;
}