#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  int d, e;
  scanf("%ld %d %d", &n, &d, &e);
  long tmp_e = n;
  int cnt = 0;
  while (5 * e * cnt <= n) {
    tmp_e = min(tmp_e, (n - 5 * e * cnt) % d);
    cnt++;
  }
  printf("%ld\n", tmp_e);
}
