#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(10);
  int n, a, b;
  cin >> n >> a >> b;
  int sol = n;
  for (int i = 0; i <= n / a; i++) {
    int rem = n - i * a;
    int cnt = rem / b;
    cnt -= cnt % 5;
    rem -= cnt * b;
    sol = min(sol, rem);
  }
  cout << sol;
  return 0;
}
