import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.System.in; public class No521 { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); long N = Long.parseLong(inputs[0]); long K = Long.parseLong(inputs[1]); if (K == 0 || K > N) { System.out.println(0); } else { long left = K; long right = N - K + 1; if (left == right) { System.out.println(N - 1); } else { System.out.println(N - 2); } } } }