#include <bits/stdc++.h>
using namespace std;
void logf(istream_iterator<string> it) {}
template <typename T, typename... Args>
void logf(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  logf(++it, args...);
}
const double PI = acos(-1);
void solve() {
  int n;
  cin >> n;
  ;
  int a;
  cin >> a;
  ;
  int b;
  cin >> b;
  ;
  b *= 5;
  vector<bool> dp(n + 1 + max(a, b));
  dp[0] = true;
  int ma = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[i]) {
      dp[i + a] = true;
      dp[i + b] = true;
      ma = i;
    }
  }
  cout << n - ma << endl;
}
int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
}
