/*
 * Created on 01.12.2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author B21
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

import java.io.*;

public class irrelevant {

	public static void main(String[] args) throws IOException {
		StreamTokenizer in = new StreamTokenizer(new FileReader("irrelevant.in"));
		in.nextToken(); int n = (int) in.nval;
		in.nextToken(); int m = (int) in.nval;
		long[] a = new long[n], b = new long[n];
		a[0] = 1;
		for (int i = 2; i <= n; i++) {
			b[0] = 1;
			for (int j = 1; j < i - 1; j++) {
				b[j] = a[j - 1] + a[j];
			}
			b[i - 1] = 1;
			long[] t = b; b = a; a = t;
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			long v = a[i] % m;
			if (v == 0)
				cnt++;
			a[i] = v;
		}		
		FileWriter out = new FileWriter("irrelevant.out");
		out.write(Integer.toString(cnt) + "\r\n");
		for (int i = 0; i < n; i++)
			if (a[i] == 0)
				out.write(Integer.toString(i + 1) + ' ');
		out.close();
	}
}
