import java.util.*; public class paiza7 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int D = sc.nextInt(); int K = sc.nextInt(); if(K==0 || K>D){ System.out.println(0); } if(((1+D)/2)==K){ System.out.println(D-1); }else{ System.out.println(D-2); } } }