package no521; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long k = sc.nextLong(); if (1 <= k && k <= n) { if (k * 2 - 1 == n) { System.out.println(n - 1); }else{ System.out.println(n - 2); } }else{ System.out.println(0); } } }