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