N, K = map(int, input().split()) if 0 < K <= N: print(N - 2 + (N == K*2-1)) else: print(0)