#include int N,D; int main(){ int ans; scanf("%d %d",&N,&D); if(N%2==0){ if(D==1)ans=N-1; else if(D==N)ans=0; else ans=N/2; } else{ if(D==N)ans=0; else ans=N-1; } printf("%d\n",ans); return 0; }