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