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