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