#include <stdio.h>
#include <vector>
#include <math.h>
#define PLIMIT 100000000
int binarySearch(std::vector<int> &v, int low, int high, int x) {
if (low > high)
return -1;
int mid = low + (high - low) / 2;
if (v[mid] <= x && x < v[mid + 1])
return mid;
if (x < v[mid])
return binarySearch(v, low, mid - 1, x);
return binarySearch(v, mid + 1, high, x);
}
int exactBinarySearch(std::vector<int> &v, int low, int high, int x) {
if (low > high)
return -1;
int mid = low + (high - low) / 2;
if (v[mid] == x)
return mid;
if (x < v[mid])
return exactBinarySearch(v, low, mid - 1, x);
return exactBinarySearch(v, mid + 1, high, x);
}
int factorial(std::vector<int> &n_fives, int P) {
int N = 0, size = n_fives.size(), current, cP, exponent;
while (P != 0) {
current = binarySearch(n_fives, 0, size, P);
if (current < 0)
return current;
exponent = (int) pow(5, current);
cP = P / n_fives[current];
N += exponent * cP;
P %= n_fives[current];
}
return N;
}
int main(void) {
int N, P, i = 1, plusFives, size;
FILE *fin = fopen("fact.in", "r");
fscanf(fin, "%d", &P);
fclose(fin);
std::vector<int> numberOf5s;
numberOf5s.push_back(0);
while (true) {
numberOf5s.push_back(5 * numberOf5s[i - 1] + 1);
if (numberOf5s[i] > PLIMIT)
break;
i++;
}
/*std::vector<int> notPossible;
notPossible.push_back(5);
for (int k = 50; k <= 10 * P; k += 25) {
printf("Pentru %d:\n", k);
notPossible.push_back(notPossible[notPossible.size() - 1] + 6);
printf("\tel = %d\n", notPossible[notPossible.size() - 1]);
N = k / 25;
while (N % 5 == 0) {
notPossible.push_back(notPossible[notPossible.size() - 1] + 1);
printf("\t\tel = %d\n", notPossible[notPossible.size() - 1]);
N /= 5;
}
}
if (exactBinarySearch(notPossible, 0, notPossible.size() - 1, P) > -1)
N = -1;
else*/
N = factorial(numberOf5s, P);
FILE *fout = fopen("fact.out", "w");
fprintf(fout, "%d", N);
fclose(fout);
return 0;
}