#include <bits/stdc++.h>
using namespace std;
long long absk(long long k) {
  if (k < 0) {
    return -k;
  }
  return k;
}
int32_t main() {
  long long n, d, r;
  cin >> n >> d >> r;
  r = r * 5;
  long long ans = 1e18;
  for (long long i = 0; i * r <= n; ++i) {
    ans = min(ans, (n - i * r) % d);
  }
  cout << ans << "\n";
}
