package yukicoder; import java.util.Scanner; public class No526 { private long n, m, fib1, fib2, fib3; public static void main(String[] args) { No526 main = new No526(); main.run(); } private void run() { Scanner sc = new Scanner(System.in); n = sc.nextLong(); m = sc.nextLong(); fib1 = 0; fib2 = 1; for(int i = 0; i < n - 2; i++) { fib3 = (fib1 + fib2) % m; fib1 = fib2; fib2 = fib3; } if(n == 1) { System.out.println(0); } else if(n == 2) { System.out.println(1 % m); } else { System.out.println(fib3 % m); } } }