package m.shin; import java.util.Scanner; public class Con521 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt() , k = s.nextInt(); s.close(); if(k == 0 || k > n){ System.out.println(0); }else if(n % 2 == 1 && k == (n+1)/2){ System.out.println(n-1); }else{ System.out.println(n-2); } } }