#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 9;
const double PI = acos(-1);
int go[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  b *= 5;
  int m = n / b, ans = 0x3f3f3f3f;
  for (int i = (0); i <= (m); ++i) ans = min(ans, (n - i * b) % a);
  cout << ans << '\n';
  return 0;
}
