#include using namespace std; int main() { int w,d; cin >> w >> d; do w-=w/d/d; while(--d>1); cout << w << endl; return 0; }