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