# include <iostream.h>
# include <fstream.h>
ifstream input("irrelevant.in");
ofstream output ("irrelevant.out");
__int64 *a;
int *b;


int main()
{
	int n,m;
	int y,i,j,l,k;

	__int64 x;
	int count=0 ;
	int index=-1;
	int N;


	input>>N>>m;

	n=N-1;
b=new int [n];
	for (k=1;k<=n;k++)
	{
		x=0;

	

		a=new __int64[k+1];
		
		for (i=0;i<k;i++)
		{
			a[i]=__int64 (n-i);
		
		}

		
		
		
		for (i=k;i>1;i--)
		{
			for (j=0;j<k+1;j++)
			{
				if (a[j]%i==0)
				{
					a[j]/=i;
					break;
			
				}
			}

			
		}






	
		x=a[0]%m;
		for (i=1;i<k;i++)
		{
			x=(x*(a[i]%m))%m;
		}





		if (x==0)
		{
			index++;
			count++;
			b[index]=k;
	
		}
	
	}
	output<<count;
	output<<endl;
	


	for (i=0;i<=index;i++)
		output<<b[i]+1<<" ";



	return 0;
}




	


















