#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000005;
struct FenwickTree {
int treeSize;
vector<int> nodes;
void init(int treeSize) {
this->treeSize = treeSize;
nodes.assign(treeSize + 1, 0);
}
void update(int id, int val) {
for (++id; id <= treeSize; id += (id & -id)) {
nodes[id] = max(nodes[id], val);
}
}
int get(int id) {
int result = 0;
for (++id; id >= 1; id -= (id & -id)) {
result = max(result, nodes[id]);
}
return result;
}
};
int n, mod;
int fibonacci[MAX_N];
FenwickTree fenwickTree;
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] = fibonacci[2] = 1;
for (int i = 3; i <= n; ++i) {
fibonacci[i] = (fibonacci[i - 2] + fibonacci[i - 1]) % mod;
}
fenwickTree.init(mod + 1);
for (int i = 1; i <= n; ++i) {
fenwickTree.update(fibonacci[i], fenwickTree.get(fibonacci[i]) + 1);
}
cout << fenwickTree.get(mod) << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiAgICBjb25zdCBpbnQgTUFYX04gPSAxMDAwMDA1OwoKICAgIHN0cnVjdCBGZW53aWNrVHJlZSB7CiAgICAgICAgaW50IHRyZWVTaXplOwogICAgICAgIHZlY3RvcjxpbnQ+IG5vZGVzOwoKICAgICAgICB2b2lkIGluaXQoaW50IHRyZWVTaXplKSB7CiAgICAgICAgICAgIHRoaXMtPnRyZWVTaXplID0gdHJlZVNpemU7CiAgICAgICAgICAgIG5vZGVzLmFzc2lnbih0cmVlU2l6ZSArIDEsIDApOwogICAgICAgIH0KCiAgICAgICAgdm9pZCB1cGRhdGUoaW50IGlkLCBpbnQgdmFsKSB7CiAgICAgICAgICAgIGZvciAoKytpZDsgaWQgPD0gdHJlZVNpemU7IGlkICs9IChpZCAmIC1pZCkpIHsKICAgICAgICAgICAgICAgIG5vZGVzW2lkXSA9IG1heChub2Rlc1tpZF0sIHZhbCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGludCBnZXQoaW50IGlkKSB7CiAgICAgICAgICAgIGludCByZXN1bHQgPSAwOwogICAgICAgICAgICBmb3IgKCsraWQ7IGlkID49IDE7IGlkIC09IChpZCAmIC1pZCkpIHsKICAgICAgICAgICAgICAgIHJlc3VsdCA9IG1heChyZXN1bHQsIG5vZGVzW2lkXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICB9OwoKICAgIGludCBuLCBtb2Q7CiAgICBpbnQgZmlib25hY2NpW01BWF9OXTsKICAgIEZlbndpY2tUcmVlIGZlbndpY2tUcmVlOwoKICAgIGludCBtYWluKCkgewogICAgICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgICAgICBjaW4udGllKDApOwogICAgICAgIGNvdXQudGllKDApOwoKICAgICAgICBmcmVvcGVuKCJMSVNGSUJPLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIkxJU0ZJQk8ub3V0IiwgInciLCBzdGRvdXQpOwoKICAgICAgICBjaW4gPj4gbiA+PiBtb2Q7CgogICAgICAgIGZpYm9uYWNjaVsxXSA9IGZpYm9uYWNjaVsyXSA9IDE7CiAgICAgICAgZm9yIChpbnQgaSA9IDM7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgICAgIGZpYm9uYWNjaVtpXSA9IChmaWJvbmFjY2lbaSAtIDJdICsgZmlib25hY2NpW2kgLSAxXSkgJSBtb2Q7CiAgICAgICAgfQoKICAgICAgICBmZW53aWNrVHJlZS5pbml0KG1vZCArIDEpOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgICAgICBmZW53aWNrVHJlZS51cGRhdGUoZmlib25hY2NpW2ldLCBmZW53aWNrVHJlZS5nZXQoZmlib25hY2NpW2ldKSArIDEpOwogICAgICAgIH0KCiAgICAgICAgY291dCA8PCBmZW53aWNrVHJlZS5nZXQobW9kKSA8PCAnXG4nOwoKICAgICAgICByZXR1cm4gMDsKICAgIH0=