#include int main() { long a,b; std::cin >> a >> b; long ans=1; if (a<=b) std::cout << 0 << std::endl; else { for (int i=a;i>0;i--) { ans*=a; ans%=b; } std::cout << ans << std::endl; } }