#include <bits/stdc++.h>
const int M = 1e5 + 8;
const int oo = 1e9 + 7;
using namespace std;
int n, D, E;
int _calc(int i) { return ((n - E * i) / D); }
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> D >> E;
  int tmp = (n / E) / 5, Res = oo;
  tmp *= 5;
  for (int i = tmp; i >= 0; i -= 5) {
    Res = min(Res, n - E * i - D * _calc(i));
  }
  cout << Res;
  return 0;
}
