#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  int n, d, e, ret, k, v;
  ret = 1e9;
  cin >> n >> d >> e;
  if (n % d == 0 || n % (5 * e) == 0) {
    cout << 0;
    return 0;
  }
  if (n < e && n < d) {
    cout << n;
    return 0;
  }
  for (int i = 0; i <= (n / d); i++) {
    v = (n - (d * i)) / (5 * e);
    k = n - (i * d) - (v * 5 * e);
    ret = k >= 0 ? min(ret, k) : ret;
  }
  cout << ret;
  return 0;
}
