#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long inf = 1e18;
const long double eps = 1e-9;
long long pow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, d, e;
  cin >> n >> d >> e;
  long long a = d;
  long long b = 5 * e;
  long long ans = n;
  for (long long x = 0; x <= n / d; x++) {
    ans = min(ans, (n - (x * d)) % b);
  }
  cout << ans;
  return 0;
}
