#include <bits/stdc++.h>
using namespace std;
const long long BIG = 1000000000000000000LL;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
void solve() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long res = n;
  for (long long i = (0); i < (n + 5); ++i) {
    long long x = n - (5 * i * b);
    if (x < 0) break;
    res = min(res, (x % a));
  }
  cout << res << "\n";
}
