#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int ret = 0, f = 0;
  char c = gc();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = gc();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = gc();
  }
  if (f) return -ret;
  return ret;
}
int main() {
  int n, d, e;
  int ans = inf;
  scanf("%d%d%d", &n, &d, &e);
  for (int i = 0; i <= 1e7; i++) {
    int tmp = n;
    tmp -= i * d;
    if (tmp > 0) tmp -= tmp / (e * 5) * (e * 5);
    if (tmp >= 0) ans = min(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
