box, th = gets.chomp.split(' ').map(&:to_i) list = Array.new box.times{ list << 1 } list[th - 1], list[-th] = 0, 0 list[0..list.length] = 0 if th == 0 || th > box puts list.count(1)