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