#include #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; typedef long long ll; typedef pair PL; typedef pair P; const int INF = 1e9; const ll MOD = 1e9 + 7; const double eps = 1e-6; int main() { ll N,M; cin >> N >> M; ll x = 0,y = 1; rep(i,N - 2){ x = (x + y)%M; swap(x,y); } cout << y << endl; }