import java.util.Scanner; public class Main { public static void main(String[] args){ Main main = new Main(); main.solveB(); } private void solveB() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int pp = 0; int p = 1; for (int n = 3; n <= N; n++) { int now = (pp + p) % M; pp = p; p = now; } System.out.println(p); } }