#include int main(void) { int n, m, i; int f1 = 0, f2 = 1, fb, t; scanf("%d %d", &n, &m); for (i = 3; i <= n; i++) { t = f2 >> 1; fb = (((f1 + t) % m) + (f2 - t)) % m; f1 = f2; f2 = fb; } printf("%d\n", fb); return 0; }