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