#!/usr/bin/env python3 n, k = map(int, input().split()) if k == 0 or n < k: ans = 0 else: if 2*k-1 == n: ans = n-1 else: ans = n-2 print(ans)