#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
char str[20];
int n,a[20],f[1200005],ans=-1;
int main(){
	cin>>str+1;
	n=strlen(str+1);
	for(int i=1;i<=n;i++)a[i]=str[i]-'0';
	for(int i=1;i<=n;i++){
		f[1<<i-1]=a[i];
		if(f[i]%3==0)ans=max(ans,1);
	}
	for(int i=1;i<(1<<n);i++){
		if(__builtin_popcount(i)==1)continue;
		f[i]=f[i&-i]+f[i-(i&-i)];
		if(f[i]%3==0)ans=max(ans,__builtin_popcount(i));
	}
	if(ans==-1)cout<<ans;
	else cout<<n-ans;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i, n)	for(ll i=0;i<(ll)(n);i++)
#define ALL(a)	(a).begin(),(a).end()
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

ll pow2(ll n, ll a){
    ll res=1;
    rep(i,a) res*=n;
    return res;
}

int main(){
    ll n;
    cin>>n;
    ll s=1e18;
    for(ll a=1;pow2(3,a)<=s;a++){
        for(ll b=1;pow2(5,b)<=s;b++){
            if(pow2(3,a)+pow2(5,b)==n){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<endl;
}