import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); long M = scan.nextLong(); scan.close(); long []F = new long[N]; F[0] = 0; F[1] = 1; for(int i = 2; i < N; i++) { F[i] = (F[i - 1] + F[i - 2]) % M; } System.out.println(F[N - 1]); } }