#include <bits/stdc++.h>
using namespace std;
long long int ar[500009], br[500009];
int main() {
  long long int a, b, c, i, j = 999999999999, k, e, f, g, w, h, i1, j1;
  string s, d;
  cin >> a >> b >> c;
  e = a;
  c = c * 5;
  j = a;
  for (i = 1;; i++) {
    a = e;
    if (a - (i * b) < 0) {
      break;
    }
    a = a - (i * b);
    a = a - ((a / c) * c);
    j = min(j, a);
  }
  for (i = 1;; i++) {
    a = e;
    if (a - (i * c) < 0) {
      break;
    }
    a = a - (i * c);
    a = a - ((a / b) * b);
    j = min(j, a);
  }
  cout << j << endl;
}
