#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, d, e;
  cin >> n >> d >> e;
  e = e * 5;
  long long int ans = n;
  for (long long int i = 0; i < (n / e) + 1; i++) {
    ans = min(ans, (n - e * i) % d);
  }
  cout << ans;
}
