#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1010;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long n, a, b;
int main() {
  while (cin >> n) {
    cin >> a >> b;
    b = 5 * b;
    int tot = n / a;
    long long ans = n;
    for (int i = 0; i <= tot; i++) {
      ans = min(ans, (n - i * a) % b);
    }
    printf("%lld\n", ans);
  }
}
