#include <bits/stdc++.h>
using namespace std;
bool dp[100000010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int d, e;
  cin >> n >> d >> e;
  e *= 5;
  dp[0] = 1;
  int ma = 0;
  for (int i = 1; i <= n; i++) {
    if (i - d >= 0 && dp[i - d]) dp[i] = true;
    if (i - e >= 0 && dp[i - e]) dp[i] = true;
    if (dp[i]) ma = i;
  }
  n = n - ma;
  cout << n << "\n";
  return 0;
}
