#include <bits/stdc++.h>
using namespace std;
int sum1, sum2;
int n, e, d;
int a[1] = {1};
int b[1] = {5};
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d >> e;
  e = e * 5;
  int ans = n;
  for (int i = 0; i <= (n / d); i++) {
    ans = min(ans, (n - i * d) % e);
  }
  printf("%d\n", ans);
}
