#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b, ans = 1e9;
  cin >> n >> a >> b;
  for (int i = 0; i * 5 * b <= n; ++i) {
    int x = i * 5 * b, j = n;
    j -= x;
    j -= ((j / a) * a);
    ans = min(ans, j);
  }
  cout << ans << '\n';
  return 0;
}
