N,K = map(int,input().split()) import sys if K == 0 or K > N: print(0) exit() if K == N - K + 1: print(N-1) else: print(N-2)