#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, A, B;
  cin >> N >> A >> B;
  B *= 5;
  long long res = N;
  for (long long i = 0; i <= 100000; i++) {
    long long r = N - B * i;
    if (r >= 0) {
      res = min(res, r % A);
    }
  }
  cout << res << endl;
}
