#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, d, e, res = INT_MAX;
  cin >> n >> d >> e;
  for (long long k = 0; n >= 5 * k * e; ++k) {
    long long y = 5 * k * e;
    res = min(res, (n - y) % d);
  }
  cout << res;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
