using System;
using System.Linq;
using System.Collections.Generic;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var k = vals[1];
        var result = 0;

        if (!(k == 1 && n == 1) && n != 0 && k != 0 && k <= n)
        {
            if (k * 2 - 1 == n)
            {
                result = n - 1;
            }
            else
            {
                result = n - 2;
            }
        }

        Console.WriteLine(result);
    }
}