#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double Pi = 3.1415926535897932;
const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  b *= 5;
  int ans = n;
  for (int i = 0; i <= n; i += a) {
    int now = (n - i) % b;
    ans = min(ans, now);
  }
  printf("%d\n", ans);
  return 0;
}
