#include int main(void){ int n, k; scanf("%d%d", &n, &k); if(k == 0 || k > n){ printf("0\n"); }else{ if(k * 2 - 1 == n){ printf("%d\n", n-1); }else{ printf("%d\n", n-2); } } return 0; }