#include <bits/stdc++.h>
using namespace std;
int n, d, e;
int main() {
  scanf("%d %d %d", &n, &d, &e);
  e *= 5;
  int ans = INT_MAX;
  int x = 1e7;
  for (int i = 0; i <= x; ++i) {
    if (i * e <= n) {
      int z = (n - i * e) % d;
      ans = min(ans, z);
    } else {
      break;
    }
  }
  printf("%d\n", ans);
}
