#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int main() {
  int n, d, e;
  cin >> n >> d >> e;
  int ans = n;
  for (int x = n / d; x >= 0; x--) {
    int cur = n - x * d;
    cur %= 5 * e;
    ans = min(cur, ans);
  }
  cout << ans;
}
