#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  long long N, D, E, r = 1e15;
  cin >> N >> D >> E;
  for (int i = 0;; i += 5) {
    long long e = i * E;
    if (e > N) break;
    long long d = (N - e) / D * D;
    r = min(r, N - e - d);
  }
  cout << r;
}
