import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long N = sc.nextLong(); final long M = sc.nextLong(); long fib = 1; long prev_fib = 0; for(int i = 2; i < N; i++){ final long next_fib = (fib + prev_fib) % M; prev_fib = fib; fib = next_fib; } System.out.println(fib); } }