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