#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, e;
  cin >> n >> d >> e;
  e *= 5;
  int ans = 1e9;
  for (int i = 0; i * e <= n; i++) {
    int lel = n;
    lel -= e * i;
    lel %= d;
    ans = min(ans, lel);
  }
  cout << ans << endl;
}
