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