using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Competitive_Programming { class MainClass { Scanner sc; static void Main(string[] args) { new MainClass().solve(); } void solve() { sc = new Scanner(); int N = sc.NextInt(); int K = sc.NextInt(); int ans; if (K == 0 || K > N) { ans = 0; } else { if (N % 2 == 1 && (N + 1) / 2 == K) { ans = N - 1; } else { ans = N - 2; } } Console.WriteLine(ans); } } class Scanner { Queue buf; public Scanner() { buf = new Queue(); this.GetBuf(); } private void GetBuf() { if (buf.Count == 0) { string[] stringArray = Console.ReadLine().Split(new char[] { ' ' }); foreach (string e in stringArray) { buf.Enqueue(e); } } } public int NextInt() { this.GetBuf(); return int.Parse(buf.Dequeue()); } public long NextLong() { this.GetBuf(); return long.Parse(buf.Dequeue()); } public double NextDouble() { this.GetBuf(); return double.Parse(buf.Dequeue()); } public string Next() { this.GetBuf(); return buf.Dequeue(); } } }