#include <bits/stdc++.h>
int main(void) {
  long long n, d, e;
  scanf("%I64d %I64d %I64d", &n, &d, &e);
  long long result = n;
  for (long long i = 0; i <= n / (5 * e); i++) {
    result = std::min(result, (n - i * 5 * e) % d);
  }
  printf("%I64d\n", result);
}
