#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5, MXX = 23;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, d, e;
  cin >> n >> d >> e;
  long long cntd = 0, ans = mod, cnte = 0;
  while ((cntd + 1) * d <= n) cntd++;
  while (e * (cnte + 5) <= n - cntd * d) cnte += 5;
  ans = min(ans, n - cntd * d - cnte * e);
  while (cntd--) {
    while (e * (cnte + 5) <= n - cntd * d) cnte += 5;
    ans = min(ans, n - cntd * d - cnte * e);
  }
  cout << ans << endl;
  return 0;
}
