#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, e;
  cin >> n >> d >> e;
  long long a = n, b = n, i;
  e = 5 * e;
  for (i = 0; e * i <= n; i++) {
    a = min(a, (n - (e * i)) % d);
  }
  for (i = 0; d * i <= n; i++) {
    b = min(b, (n - (d * i)) % e);
  }
  cout << min(a, b);
}
