import java.io.*; import java.util.*; import java.util.stream.*; // 処理 class Process { private int N; private int K; Process(int N, int K) { this.N = N; this.K = K; } int getResult() { if((K == 0) || (K > N)) { return 0; } if(N % 2 == 0) { return (N - 2); } return ((K == ((N + 1) / 2)) ? (N - 1) : (N - 2)); } } public class Main { public static void main(String[] args) throws IOException { var bufferedReader = new BufferedReader(new InputStreamReader(System.in)); var printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 入力 int[] input = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray(); // 出力 printWriter.println((new Process(input[0], input[1])).getResult()); bufferedReader.close(); printWriter.close(); } }