#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  a *= 1;
  b *= 5;
  int ans = n;
  for (int i = 0; i <= n; i += a) {
    ans = min(ans, (n - i) % b);
  }
  cout << ans << endl;
}
