/*                                بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ

                                    ( إِنِ الْحُكْمُ إِلَّا لِلَّهِ )

*/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x           first
#define y           second
#define read(n,a)   for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n)  for(ll i=z;i<n;i++)
#define rrep(i,z,n) for(ll i=z-1;i>=n;i--)
#define all(v)      v.begin(),v.end()
#define clr(v,d)    memset(v,d,sizeof(v));


ll  a[200004];
ll  b[200004];

//int dx[] = {0, 0, 1,1, 1,-1,-1,-1};
//int dy[] = {1,-1, 0,1,-1, 0,1 ,-1};
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

string s, ss;

ll n,m,k,w;
ll  ans ,ans1;
ll mod = 1e9 +7;


int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        s=to_string(n);
        m=s.size();
        ans=1e9;
        rep(i,0,(1<<m)-1)
        {
            k=0;
            w=0;
            rep(j,0,m)
            {
                if(i& 1<<j)continue;
                k*=10;
                k+=s[j]-'0';
                k%=3;
                w++;
            }
            if(k%3==0)ans=min(ans,m-w);
        }
        if(ans==1e9)ans=-1;
        cout<<ans;
    }
    return 0;
}

/* HARE KRSNA HARE KRSNA KRSNA KRSNA HARE HARE
    HARE RAMA HARE RAMA RAMA RAMA HARE HARE  */

#include<bits/stdc++.h>
using namespace std;

#define nl "\n"
#define ff first
#define ss second
#define pp pop_back
#define pf pop_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define test ll t; cin>>t; while(t--)
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define rloop(i,s,n) for(ll i=s;i>=n;i--)
#define fill(a,value) memset(a,value,sizeof(a))

#define debug1(a,n)  loop(i,0,n)  cout<<a[i]<<" ";  cout<<nl;
#define debug2(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define debug4(a)  for(auto x : a)  cout<<x.ff<<" "<<x.ss<<nl;
#define debug3(a,n,m)  loop(i,0,n){ loop(j,0,m)	cout<<a[i][j]<<" ";	cout<<nl; }

typedef long long ll;
typedef long double ld;

typedef stack<ll> sll;
typedef queue<ll> qll;
typedef deque<ll> dll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<ll, pll> ppll;
typedef vector<vector<ll>> vvll;
typedef priority_queue<ll> pqll;

const ll mod = 1000000007;
const ll mod2 = 998244353;
const ld pi =  3.1415926535; //acos((ld) - 1);

set<string> S;

void rec(string s, ll len)
{
	if (!len)
	{
		S.insert(s);
		return;
	}
	rec(s + '1', len - 1);
	rec(s + '0', len - 1);
}

void solve()
{
	string n;	cin >> n;
	rec("", n.size());
	// debug2(S);

	ll ans = 9e18;

	for (auto x : S)
	{
		if ((ll)count(all(x), '0') == x.size())	continue;
		ll sum = 0;
		// cout << x << nl;
		loop(i, 0, x.size())
		{
			if (x[i] == '1')	sum += (n[i] - 48);
		}
		if (sum && sum % 3 == 0)
		{
			ans = min(ans, (ll)count(all(x), '0'));
			// cout << sum << " " << x << nl;
		}
	}

	if (ans == 9e18)		ans = -1;

	cout << ans << nl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}
