#include main(){ int N,K; scanf("%d%d",&N,&K); printf("%d\n",K>N||K==0?0:N%2==1&&N/2==K-1?N-1:N-2); }