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