N, K = [int(i) for i in input().strip().split(' ')] if K == 0 or K > N: print('0') exit(0) ans = N - 2 if (N+1) / 2 == K: ans += 1 print(ans)