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); long N = sc.nextLong(); long M = sc.nextLong(); long pp = 0; long p = 1; for (int n = 3; n <= N; n++) { long now = (pp + p) % M; pp = p; p = now; } System.out.println(p); } }