#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
long long n, k, m, d;
int main() {
  cin >> n >> k >> m >> d;
  long long ans = min(n, m);
  for (long long i = 1; i <= d; i++) {
    long long tmp = (i - 1) * k + 1;
    if (tmp <= 0) continue;
    long long x = n / tmp;
    if (x > m) x = m;
    if (x * (i - 1) > (n - x) / k) continue;
    long long res = x * (i - 1) + x;
    if (res > ans) {
      ans = res;
    }
  }
  cout << ans << endl;
  return 0;
}
