import java.util.Scanner; class no521{ public static void main(String[] args) { Scanner stdIn=new Scanner(System.in); int n=stdIn.nextInt(),k=stdIn.nextInt(); if(k==0||k>n) n=0; else if(n%2!=0) { if((n+1)/2==k) n--; else n-=2; } else n-=2; System.out.print(n); } }