#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, e, d;
  cin >> n >> d >> e;
  ll ans = n;
  for (int i = 0; i * e * 5 <= n; ++i) {
    ans = min(ans, (n - i * e * 5) % d);
  }
  cout << ans << endl;
  return 0;
}
