# -*- coding: utf-8 -*- """ No.521 Cheeses and a Mousetrap(チーズとネズミ捕り) https://yukicoder.me/problems/no/521 """ import sys from sys import stdin input = stdin.readline def solve(N, K): if K == 0 or K > N: return 0 if K*2 == N+1: return N - 1 return N - 2 def main(args): N, K = map(int, input().split()) ans = solve(N, K) print(ans) if __name__ == '__main__': main(sys.argv[1:])