#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <cassert>
//#include <vector>
#include <algorithm>

#define MAXN 100010

int a[2][MAXN] = {0};
int n = 0, m = 0;

int main ()
{
	int count = 0, ccc;
	int i = 0, ii;
	int k = 0;

	freopen ("irrelevant.in", "rt", stdin);
	freopen ("irrelevant.out", "wt", stdout);
	
	a[k][1] = 1;
	
	scanf("%d %d", &n, &m);

	for (count = 2; count <= n; count++)
	{
		k = 1 - k;
		for (i = 1; i <= ((count + 1) >> 1); i++)
		{
			ii = i;
			ccc = (count) >> 1;
			if (ii > ccc)
				if (((count-1) & 1) == 0)
					ii = ccc;
				else
					ii = ccc-1;
			a[k][i] = (a[1-k][i - 1] + a[1-k][ii]);
			while (a[k][i] >= m)
				a[k][i] -= m;
			//printf ("%d,%d = %d\n", count, i, a[k][i]);
		}
	}

	int num = 0;
	int cc1 = ((count) >> 1);
	int cc2 = ((count - 1) >> 1);

	for (i = 1; i <= cc1; i++)
		if (0 == a[k][i])
			num++;
	for (i = cc2; i >= 1; i--)
		if (0 == a[k][i])
			num++;

	printf("%d\n", num);

	for (i = 1; i <= cc1; i++)
		if (0 == a[k][i])
			printf("%d ", i);
	for (i = cc2; i >= 1; i--)
		if (0 == a[k][i])
			printf("%d ", cc1+(cc2-i+1));

/*	printf("\n");
	printf("%d\n", count);
	for (i = 1; i <= count; i++)
			printf("%d ", a[i]);
*/
	fclose (stdin);
	fclose (stdout);
	return 0;
}