#include <bits/stdc++.h>
using namespace std;
int inf = 2e9;
int mod = 1e9 + 7;
int main() {
  cout.tie(0), cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, d, e, res = 0;
  cin >> n >> d >> e;
  vector<int> dp(n + 1);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (i >= d) dp[i] = dp[i - d];
    if (i >= 5 * e) dp[i] = max(dp[i], dp[i - 5 * e]);
    if (dp[i] != 0) res = i;
  }
  cout << n - res << endl;
  return 0;
}
