import java.util.*; import java.io.*; import java.math.*; public class No526 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); long[] f = new long[n]; f[0] = 0; f[1] = 1; for(int i = 2; i < n; i++){ f[i] = (f[i - 1] + f[i - 2]) % m; } System.out.println(f[n - 1]); } }