#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pl; int main() { ll N, D,ans; cin >> N >> D; if (N == D) ans = 0; else if (N % D == 0) ans = N / D - 1; else if (N % 2 == 1 || (N % 2 == 0 && D % 2 == 1)) ans = N - 1; else ans = N / 2 -1; cout << ans << endl; return 0; }