#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn = 2e3 + 7;
int32_t main() {
  int n, d, e;
  cin >> n >> d >> e;
  int ans = 1e9 + 7;
  for (int i = 1; i * 5 * e <= n; i++) {
    int t = i * 5 * e;
    t = n - t;
    t %= (d);
    ans = min(ans, t);
  }
  int t = n % d;
  ans = min(ans, t);
  cout << ans << endl;
}
