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