#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main() {
	long long n, m;
	std::cin >> n >> m;
	long long f0 = 0;
	long long f1 = 1;
	n--;
	while (n--) {
		long long f2 = (f0 + f1) % m;
		f0 = f1;
		f1 = f2;
	}
	std::cout << f0 << std::endl;
}