#include <bits/stdc++.h>
using namespace std;
mt19937 tw(960172);
long long rnd(long long x, long long y) {
  static uniform_int_distribution<long long> d;
  return d(tw) % (y - x + 1) + x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, d, e;
  cin >> n >> d >> e;
  e *= 5;
  int ans = n;
  while (n >= 0) {
    ans = min(ans, n % d);
    n -= e;
  }
  cout << ans;
  return 0;
}
