import java.io.*; import java.util.*; public class Main_yukicoder521 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int k = sc.nextInt(); if (k == 0 || k > n) { pr.println(0); } else if (n % 2 == 1 && n / 2 + 1 == k) { pr.println(n - 1); } else { pr.println(Math.max(0, n - 2)); } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }