#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int n, k;
int main() {
	cin >> n >> k;
	if (k <= 0 || n < k) { cout << 0 << endl; return 0; }
	if (n == k * 2 - 1) { cout << n - 1 << endl; }
	else cout << n - 2 << endl;
	return 0;
}