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