#include using namespace std; main(){long n,k;cin>>n>>k; cout<<(k<1||k>n?0:n+1-k-k?n-2:n-1);}