#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll dp[61][1<<14];
ll pows[1<<14];
vector<ll> vec;

bool C(ll v){
	while(v>0LL){
		if(v%10LL!=2 && v%10LL!=8)return false;
		v/=10LL;
	}
	return true;
}

int main(void){
	scanf("%lld",&n);
	int cnt=0;
	while(n%2LL==0){
		cnt++;
		n/=2LL;
	}
	for(ll i=3;i*i<=n;i++){
		while(n%i==0){
			n/=i;
			vec.push_back(i);
		}
	}
	if(n!=1LL){
		vec.push_back(n);
	}
	int m=vec.size();
	for(int i=0;i<(1<<m);i++){
		ll val=1;
		for(int j=0;j<m;j++){
			if(i>>j & 1){
				val*=vec[j];
			}
		}
		pows[i]=val;
	}
	memset(dp,-1,sizeof(dp));
	if(cnt>0)dp[cnt][(1<<m)-1]=0;
	for(int i=cnt;i>0;i--){
		for(int j=0;j<(1<<m);j++){
			if(dp[i][j]==-1)continue;
			int ubit=j;
			bool fu=true;
			while(ubit!=j || fu){
				fu=false;
				ll val=pows[ubit];
				for(int k=1;k<=i;k++){
					val*=2LL;
					if(C(val)){
						dp[i-k][j-ubit]=max(dp[i-k][j-ubit],dp[i][j]+1);
					}
				}
				ubit=(ubit-1)&j;
			}
		}
	}
	printf("%lld\n",dp[0][0]);
	return 0;
} 
