#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 100000000000;
  int i = 0;
  while (1) {
    long long sum = n - i * a;
    if (sum < 0) break;
    sum = sum % (5 * b);
    ans = min(ans, sum);
    i++;
  }
  cout << ans;
  return 0;
}
