#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, e;
  cin >> n;
  cin >> d;
  cin >> e;
  int ei = e * 5;
  int num = n / ei;
  int _min = 1000000000;
  int num1;
  for (int i = 0; i <= num; i++) {
    num1 = (n - ei * i) % d;
    if (_min > num1) _min = num1;
  }
  cout << _min << endl;
  return 0;
}
