#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int sum, d, e, min_rest;
  scanf("%d", &sum);
  scanf("%d", &d);
  scanf("%d", &e);
  min_rest = sum;
  for (int j = 0; j <= sum / (e * 5); j++) {
    min_rest = min(min_rest, (sum - e * 5 * j) % d);
  }
  printf("%d", min_rest);
  return 0;
}
