import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) throws Exception { new Main().run(); } void run() { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); if(K==0||K>N) { System.out.println(0); return; } System.out.println(K==N-K+1?N-1:N-2); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }