#include #define rep(i,a,n) for (int i = a;i < n;i++) using namespace std; int main() { int n, m; cin >> n >> m; int a = 0, b = 1, c = (a + b) % m; a = b, b = c, c = (a + b) % m; rep(i, 4, n) { a = b; b = c; c = (a + b) % m; } cout << c << endl; }