use std::io::{read_to_string, stdin};

fn get_legendre(n: usize, p: usize) {
    let mut key = p;
    let mut res = 0;
    let mut curr = n / p;
    while curr == 0 {
        
    }
}

fn main() {
    let mut temp = read_to_string(stdin()).unwrap();
    let mut iter = temp
        .split_ascii_whitespace()
        .map(|x| x.parse::<usize>().unwrap());

    let n = iter.next().unwrap();
    let m = iter.next().unwrap();

    let mut combs = vec![0; n];

    combs[0] = 1;
    let mut new_combs = vec![0; n];
    new_combs[0] = 1;

    for i in 1..=n - 1 {
        for j in 1..i {
            new_combs[j] = (combs[j] + combs[j - 1]) % m;
        }
        new_combs[i] = 1;
        let ct = combs;
        combs = new_combs;
        new_combs = ct;
    }

    let res = (0..n)
        .filter(|&i| combs[i] == 0)
        .map(|i| i + 1)
        .collect::<Vec<_>>();

    println!("{}", res.len());
    for i in res {
        println!("{}", i);
    }
}
