import java.util.*; public class T02 { /* int gcd(int a, int b) { if ( b > a) return gcd(b, a); else if (b == 0) return a; eklse */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int D = sc.nextInt(); if ( N / 2 < D) { D = N - D; } if (D == 0) { System.out.println(0); } else if (N % D == 0) { System.out.println(N / D - 1); } else { System.out.println(N - 1); } } }