#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int d, e;
  cin >> d >> e;
  int ans = n, tmp = 0, tan = 0;
  int dn = n / d, en = n / e;
  for (int j = 0; j <= en; j += 5) {
    tan = j * e;
    tmp = ((n - tan) / d) * d;
    tmp += tan;
    if (tmp > n) tmp = 0;
    ans = min(ans, n - tmp);
  }
  cout << ans << endl;
  return 0;
}
