#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> graph[maxn];
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
}
int main() {
  long long n, d, e;
  cin >> n >> d >> e;
  long long ans = 1e9 + 5;
  long long tmp = n;
  while (n >= d) {
    ans = min(ans, n % (5 * e));
    n -= d;
  }
  ans = n % (5 * e);
  n = tmp;
  while (n >= 5 * e) {
    ans = min(ans, n % d);
    n -= (5 * e);
  }
  ans = min(ans, n % d);
  cout << ans << endl;
  return 0;
}
