#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int main() {
  long long int n = 0, min = 0, num = 0;
  int d = 0, e = 0;
  cin >> n >> d >> e;
  e = e * 5;
  min = n;
  for (int i = 0; i <= n / d; i++) {
    num = (n - (i * d)) % e;
    if (num >= 0 && num < min) min = num;
  }
  cout << min << endl;
  return 0;
}
