#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, e, ans = 1e8;
  scanf("%d %d %d", &n, &d, &e), e *= 5;
  for (int i = 0; i * d <= n; i++) {
    ans = min(ans, (n - i * d) % e);
  }
  printf("%d\n", ans);
  return 0;
}
