import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		long M = Long.parseLong(sc.next());
		sc.close();

		long[] f = new long[3];
		f[2] = 1;
		
		for ( int i = 3 ; i <= N ; i++ ) {
			f[i % 3] = (f[(i - 1) % 3] + f[(i - 2) % 3]) % M;
		}
		
		System.out.println(f[N % 3]);
	}
}