#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; ll N,M; int main() { scanf("%lld%lld",&N,&M); ll curr = 1,prev = 0; FOR(i,0,N - 2){ ll t = (curr + prev) % M; prev = curr; curr = t; } printf("%lld\n",curr); return 0; }