#include <bits/stdc++.h>
using namespace std;
const int base = 311;
const long long Hmod[] = {(long long)1e9 + 2277, (long long)1e9 + 5277,
                          (long long)1e9 + 8277, (long long)1e9 + 9277};
const int gh = 10;
void solve() {
  long long n, k, m, d;
  cin >> n >> k >> m >> d;
  long long maxx = 0;
  long long d2 = d;
  d = min(n / k + 1, d);
  while (d > 0) {
    long long t = n / (k * d + 1);
    long long t2 = n / (k * d);
    if (t > m) {
      long long t3 = n / m - k * d;
      if (t3 > k || t3 < 0) {
        d--;
        continue;
      }
      if (d != d2 && t3 >= 1) maxx = max(m * d + m, maxx);
      if (t3 == 0) maxx = max(m * d, maxx);
      d--;
      continue;
    }
    if (d != d2) maxx = max(maxx, t * d + t);
    if (t2 > m) {
      d--;
      continue;
    }
    if (n % (k * d) == 0) maxx = max(maxx, t2 * d);
    d--;
  }
  if (m >= n / (k + 1)) maxx = max(m, maxx);
  cout << maxx << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
