#include <bits/stdc++.h>
int main() {
  int rubs;
  int euros;
  int dollars;
  scanf("%i", &rubs);
  scanf("%i", &dollars);
  scanf("%i", &euros);
  euros *= 5;
  int min = rubs;
  int i;
  i = rubs / euros + 1;
  if (i > 1)
    while (--i >= 0 && min) {
      if ((rubs - i * euros) % dollars < min)
        min = (rubs - i * euros) % dollars;
    }
  else {
    i = rubs / dollars + 1;
    while (--i >= 0 && min) {
      if ((rubs - i * dollars) % euros < min)
        min = (rubs - i * dollars) % euros;
    }
  }
  printf("%d", min);
  return (0);
}
