import java.io.*; import java.util.*; public class Main_yukicoder526 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int m = sc.nextInt(); int[] f = new int[n]; f[0] = 0; f[1] = 1; for (int i = 2; i < n; i++) { f[i] = (int)(((long)f[i - 1] + f[i - 2]) % m); } pr.println(f[n - 1]); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }