import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; import java.util.TreeSet; public class Main { public static int RANGE = 100; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long N = sc.nextLong(); final long K = sc.nextLong(); if(K <= 0 || K > N){ System.out.println(0); }else if(N % 2 == 1 && (K - 1) == (N / 2)){ System.out.println(N - 1); }else{ System.out.println(N - 2); } } }