#include <bits/stdc++.h>
using namespace std;
int a[11] = {1, 2, 5, 10, 20, 100};
int b[11] = {5, 10, 20, 50, 100, 200};
signed main() {
  int n, e, d;
  scanf("%d%d%d", &n, &d, &e);
  e *= 5;
  int ans = 999999999;
  for (int i = 0; i <= n / e; i++) {
    int tote = e * i;
    ans = min(ans, (n - tote) % d);
  }
  printf("%d", ans);
  return 0;
}
