import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); long k = in.nextLong(); long ans = 0; if(!(k == 0 || k > n )) { long mid = (n+1) / 2; if(mid != k) ans = n - 2; else if(mid == k) { if(n % 2 == 0) ans = n - 2; else ans = n - 1; } } System.out.println(ans); } }