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