#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = (1 << 30);
vector<long long> d;
int solve(int pos, long long cur) {
	if (pos == d.size()) return -inf;
	if (cur == 1) return 0;
	int ret = solve(pos + 1, cur);
	if (cur % d[pos] == 0) ret = max(ret, solve(pos, cur / d[pos]) + 1);
	return ret;
}
int main() {
	long long n;
	cin >> n;
	for (int i = 1; i <= 18; ++i) {
		for (int j = 0; j < (1 << i) - 1; ++j) {
			long long cur = 0;
			for (int k = 0; k < i; ++k) {
				cur = cur * 10 + (((j >> k) & 1) ? 8 : 2);
			}
			if (n % cur == 0) {
				d.push_back(cur);
			}
		}
	}
	int ans = solve(0, n);
	cout << (ans >= 0 ? ans : -1) << endl;
	return 0;
}
