#include<cstdio>
#define maxn 100000
using namespace std;
typedef long long ll;
ll s[maxn]={0},n,m,ans=0;
int main(){
freopen("irre.in","r",stdin);
freopen("irre.out","w",stdout);
scanf("%lld%lld",&n,&m);
s[1]=1;
for (int i=1;i<=n;i++){
for (int j=i;j>=1;j--){
s[j]=(s[j]+s[j-1])%m;
}
}
for (int i=1;i<=n;i++) if (s[i]==0) ans++;
printf("%lld\n",ans);
for (int i=1;i<=n;i++) if (s[i]==0) printf("%lld ",i);
return 0;
}