#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
int ans=1e9;
string s;
void go(int cur,vector<bool> is,int n)
{
    if(cur==n)
    {
        string got="";
        int p=0;
        forn(i,s.size())
        {
            if(is[i])
            {
                got+=s[i];
            }
            else
            {
                p++;
            }
        }
        if(got.size()==0)return;
        ll x=stoll(got);
        if(x%3==0)
        {
            ans=min(ans,p);
        }
        return;
    }
    is[cur]=false;
    go(cur+1,is,n);
    is[cur]=true;
    go(cur+1,is,n);
}
void solve()
{
    //string s;
    cin>>s;
    vector<bool> is(s.size(),1);
    go(0,is,s.size());
    if(ans==1e9)ans=-1;
    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
	solve();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
char num[20];
int n,cnt[5],sum;
int main(){
	scanf("%s",num);
	n=strlen(num);
	for(int i=0;i<n;++i)
		++cnt[(num[i]-'0')%3];
	sum=(cnt[1]+cnt[2]*2)%3;
	if(sum==0){
		printf("0\n");
		return 0;
	}
	if(sum==1){
		if(cnt[1]){
			if(n<=1)
				printf("-1\n");
			else
				printf("1\n");
		}
		else if(cnt[2]>=2){
			if(n<=2)
				printf("-1\n");
			else
				printf("2\n");
		}
	}
	else{
		if(cnt[2]){
			if(n<=1)
				printf("-1\n");
			else
				printf("1\n");
		}
		else if(cnt[1]>=2){
			if(n<=2)
				printf("-1\n");
			else
				printf("2\n");
		}
	}
}