import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int k = Integer.parseInt(first[1]); if (k == 0 || k > n) { System.out.println(0); } else { if (n % 2 == 1 && (n + 1) / 2 == k) { System.out.println(n - 1); } else { System.out.println(n - 2); } } } }