#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MAXN = 0x7fffffff;
void file() {}
void pr(bool num) { cout << (num == 1 ? "YES" : "NO") << "\n"; }
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  file();
  long long n, d, e;
  while (cin >> n >> d >> e) {
    long long ans = INF;
    long long num = n % d % (e * 5);
    ans = min(num, ans);
    num = n % (e * 5) % d;
    ans = min(num, ans);
    long long k = n / d;
    num = n % d;
    for (long long i = 1; i <= k; i++) {
      long long temp = (i * d + num) % (e * 5);
      ans = min(ans, temp);
    }
    cout << ans << "\n";
  }
  return 0;
}
