import java.util.Scanner; public class N521 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); int max=0; if(K==0||K>N) { max=0; } else { if((N%2)==1&&((K==(N+1)/2))) { max=N-1; } else { max=N-2; } } System.out.println(max); } }