#include using namespace std; long long int f[5000001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long int n,m; cin >> n >> m; f[1] = 0; f[2] = 1; for(int i=3;i<=n;i++) { f[i] = f[i-1] + f[i-2]; f[i]%=m; } cout << f[n] << '\n'; return 0; }