class Program { static void Main(string[] args) { string[] input = Console.ReadLine()!.Split(' '); int total = int.Parse(input[0]); int outNum = int.Parse(input[1]); if (outNum == 0 || outNum > total) { Console.WriteLine(0); } else if (total % 2 == 0) { Console.WriteLine(total - 2); } else { if (outNum == total / 2 + 1) { Console.WriteLine(total - 1); } else { Console.WriteLine(total - 2); } } } }