import java.util.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { long n = sc.nextLong(); long d = sc.nextLong(); long ret; if (n==d) { ret = 0; } else { if (d>n/2) d = n-d; long m = n%d; if (m==0) { ret = n/d-1; } else { ret = n-1; } } System.out.println(ret); } }