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; if (k == 0 || k > n) { ans = 0; } else if (k % 2 == 1 && (n + 1) / 2 == k) { ans = n - 1; } else { ans = n - 2; } System.out.println(ans); } }