#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
int n, mod;
int fibonacci[MAX_N], dp[MAX_N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("LISFIBO.inp", "r", stdin);
freopen("LISFIBO.out", "w", stdout);
cin >> n >> mod;
fibonacci[1] = 1;
fibonacci[2] = 1;
for (int i = 3; i <= n; ++i) {
fibonacci[i] = (fibonacci[i - 2] + fibonacci[i - 1]) % mod;
}
int res = 0;
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
for (int j = 1; j < i; ++j) {
if (fibonacci[j] <= fibonacci[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
res = max(res, dp[i]);
}
cout << res << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiAgICBjb25zdCBpbnQgTUFYX04gPSAxMDA1OwoKICAgIGludCBuLCBtb2Q7CiAgICBpbnQgZmlib25hY2NpW01BWF9OXSwgZHBbTUFYX05dOwoKICAgIGludCBtYWluKCkgewogICAgICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgICAgICBjaW4udGllKDApOwogICAgICAgIGNvdXQudGllKDApOwoKICAgICAgICBmcmVvcGVuKCJMSVNGSUJPLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIkxJU0ZJQk8ub3V0IiwgInciLCBzdGRvdXQpOwoKICAgICAgICBjaW4gPj4gbiA+PiBtb2Q7CgogICAgICAgIGZpYm9uYWNjaVsxXSA9IDE7CiAgICAgICAgZmlib25hY2NpWzJdID0gMTsKICAgICAgICBmb3IgKGludCBpID0gMzsgaSA8PSBuOyArK2kpIHsKICAgICAgICAgICAgZmlib25hY2NpW2ldID0gKGZpYm9uYWNjaVtpIC0gMl0gKyBmaWJvbmFjY2lbaSAtIDFdKSAlIG1vZDsKICAgICAgICB9CgogICAgICAgIGludCByZXMgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgICAgICBkcFtpXSA9IDE7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDwgaTsgKytqKSB7CiAgICAgICAgICAgICAgICBpZiAoZmlib25hY2NpW2pdIDw9IGZpYm9uYWNjaVtpXSkgewogICAgICAgICAgICAgICAgICAgIGRwW2ldID0gbWF4KGRwW2ldLCBkcFtqXSArIDEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJlcyA9IG1heChyZXMsIGRwW2ldKTsKICAgICAgICB9CgogICAgICAgIGNvdXQgPDwgcmVzIDw8ICdcbic7CgogICAgICAgIHJldHVybiAwOwogICAgfQ==