#include <bits/stdc++.h>
using namespace std;
long long n, d, e, ans;
bool book[100000005];
signed main() {
  cin >> n >> d >> e;
  ans = n;
  e *= 5;
  book[0] = 1;
  for (register long long i = 1; i <= n; i++) {
    if (i >= d) book[i] |= book[i - d];
    if (i >= e) book[i] |= book[i - e];
    if (book[i] == 1) ans = n - i;
  }
  cout << ans << endl;
  return 0;
}
