package yukicoder; import java.math.BigInteger; import java.util.Scanner; public class No526 { private int n; private BigInteger m; private BigInteger 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.nextInt(); m = new BigInteger(sc.next()); fib1 = new BigInteger("0"); fib2 = new BigInteger("1"); if(n == 1) { System.out.println(0); return; } else if(n == 2) { System.out.println(1); return; } for(int i = 0; i < n - 2; i++) { fib3 = fib1.add(fib2); fib1 = fib2; fib2 = fib3; } System.out.println(fib3.mod(m)); } }