import java.util.Scanner; public class Main { static Scanner in = new Scanner(System.in); public static void main(String[] args) { int N = in.nextInt(), K = in.nextInt(); if (K < 1 || N < K) { System.out.println(0); } else if (K == N / 2) { System.out.println(N - 1); } else { System.out.println(N - 2); } } }