#include <bits/stdc++.h>
using namespace std;
long long const N = 5e5;
long long a[N];
void init_code() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solve() {
  long long n, d, e;
  cin >> n >> d >> e;
  long long md = n / d;
  long long me = n / (5 * e);
  long long ans = n;
  for (long long i = 0; i * 5 * e <= n; i++) {
    ans = min(ans, (n - i * 5 * e) % d);
  }
  cout << ans << "\n";
}
signed main() {
  init_code();
  long long t = 1;
  while (t--) {
    solve();
  }
}
