#include <bits/stdc++.h>
using namespace std;
template <typename T>
string to_str(T str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, d, e;
  long long result = 1000000000;
  cin >> n >> d >> e;
  while (n >= 0) {
    result = min(n % (5 * e), result);
    n = n - d;
  }
  cout << result << endl;
  return 0;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
