// Arup Guha
// 7/5/2020
// Solution to 2020 USACO March Gold Problem: Exercise

import java.util.*;
import java.io.*;

public class exercise_gold {
	
	public static int n;
	public static long mod;
	
	// Store primes.
	public static ArrayList<Integer> primes;
	
	// Store memo.
	public static long[][] memo;
	
	public static void main(String[] args) throws Exception {
		
		// Read in the array.
		Scanner stdin = new Scanner(new File("exercise.in"));
		n = stdin.nextInt();
		mod = stdin.nextLong();
		
		// Run prime sieve.
		boolean[] sieve = new boolean[n+1];
		Arrays.fill(sieve, true);
		for (int i=2; i<=n; i++)
			for (int j=2*i; j<=n; j+=i)
				sieve[j] = false;
	
		// Just store 1 and primes.
		primes = new ArrayList<Integer>();
		primes.add(1);
		for (int i=2; i<=n; i++)
			if (sieve[i])
				primes.add(i);
			
		// Now add prime powers.
		int oldPrimeSize = primes.size();
		
		// Set up memo.
		memo = new long[n+1][primes.size()];
		for (int i=0; i<=n; i++)
			Arrays.fill(memo[i], -1);
		
		// Add up with all possible starting values.
		long res = go(n, primes.size()-1);
			
		// Output to file.
		PrintWriter out = new PrintWriter(new FileWriter("exercise.out"));
		out.println(res);
		out.close();		
		stdin.close();		
	}
	
	// Returns the result for n and all primes being <= primes[pIdx].
	public static long go(int n, int pIdx) {
	
		// Only 1 left now.
		if (pIdx == 0 || n == 0) return 1;
	
		// Did this before.
		if (memo[n][pIdx] != -1) return memo[n][pIdx];
		
		// Just step down.
		if (primes.get(pIdx) > n) return memo[n][pIdx] = go(n, pIdx-1);
		
		long res = 0;
		
		// Our prime.
		int p = primes.get(pIdx);
		
		// Try each power of this prime.
		while (p <= n) {
			res = (res + (p*go(n-p, pIdx-1))%mod)%mod;
			p *= primes.get(pIdx);
		}
		
		// This is for not grabbing any of this prime.
		res = (res + go(n, pIdx-1))%mod;
		
		// Store and return.
		return memo[n][pIdx] = res;
	}
	
}