n, k = gets.split.map(&:to_i) if k == 0 || n < k puts 0 exit end if n % 2 == 1 && k == n / 2 + 1 puts n - 1 exit end puts n - 2