#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll F[5000010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	F[1] = 0, F[2] = 1;
	for(int i = 3; i <= N; i++) {
		F[i] = F[i - 1] + F[i - 2];
		F[i] %= M;
	}
	cout << F[N] << endl;
}