#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	ll f1 = 0, f2 = 1, f;
	for (int i = 3; i <= n; i++) {
		f = (f1 + f2) % m;
		f1 = f2;
		f2 = f;
	}
	cout << f << endl;
	return 0;
}