#include int main(void){ int n, m; scanf("%d%d", &n, &m); if(n == 1){ printf("0"); }else if(n == 2){ printf("1\n"); }else{ int ans1 = 0, ans2 = 1, ans3; for(int i = 2; i <= n; i++){ ans3 = ans1 + ans2; ans3 %= m; ans1 = ans2; ans2 = ans3; } printf("%d\n", ans1); } return 0; }