#include <iostream>
using namespace std;
int main() {
int r, n, k;
cin>>n>>k;
r=k>3? n*(k-3)-1 : n>1? n-1 : 1;
cout<<r;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgciwgbiwgazsKCWNpbj4+bj4+azsKCXI9az4zPyBuKihrLTMpLTEgOiBuPjE/IG4tMSA6IDE7Cgljb3V0PDxyOwoJcmV0dXJuIDA7Cn0=