#include #include #include #include #include #include #include #define rep(i,N) for(int (i)=0;(i)<(N);(i)++) #define MOD 1000000007 using namespace std; int powmod(int a, int b, int p) { if (b == 0)return 1; else if (b % 2 == 0)return (powmod(a*a, b / 2, p) % p); else return (powmod(a, b - 1, p)*a%p); } int factorialmod(int a, int p) { if (!a)return 1; else return a * factorialmod(a - 1, p) % p; } int main(){ int N, M; scanf("%d %d", &N, &M); int prev2 = 0, prev1 = 1, temp; for (int i = 0; i < N-2; i++) { temp = (prev1 + prev2) % M; prev2 = prev1; prev1 = temp; } printf("%d\n", temp); return 0; }