#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, m = INT_MAX, tmp;
  cin >> n >> a >> b;
  b *= 5;
  for (int i = (0) - ((0) > (n / a + 1));
       i != (n / a + 1) - ((0) > (n / a + 1));
       i += 2 * ((0) < (n / a + 1)) - 1) {
    tmp = n - a * i;
    m = min(m, tmp % b);
  }
  cout << m << endl;
}
