#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;
}