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