#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long ans = a % b;
  for (long long i = 1; 5 * i * c <= a; i++) {
    long long hh = a - (5 * c * i);
    ans = min(ans, hh % b);
  }
  cout << ans << endl;
  return 0;
}
