#include <cstdio>
#include <iostream>
using namespace std;
long long n;
long long k;
long long p;
void ParseIn () {
freopen ("noi2011_rabbit.in", "r", stdin);
freopen ("noi2011_rabbit.out", "w", stdout);
cin >> n >> k >> p;
}
void CoreCWriteOut () {
if (n < 3) {
cout << 1 << endl;
return;
}
long long a = 1, b = 1, c;
for (int i = 3; i <= n; i++) {
c = (a + b) % (k * p);
if (c % k == 1) {
c -= 1;
}
a = b;
b = c;
}
cout << c % p << endl;
}
int main () {
ParseIn ();
CoreCWriteOut ();
return 0;
}