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