#include using namespace std; int main(){ int n,m;cin>>n>>m; if(n < m){ cout << 0 << endl; }else{ if(m==n+1-m){ cout << n-1 << endl; }else{ cout << n-2 << endl; } } }