
// Problem: C - To 3
// Contest: AtCoder - AtCoder Beginner Contest 182
// URL: https://atcoder.jp/contests/abc182/tasks/abc182_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)     \
  for (auto x : v)    \
    cout << x << " "; \
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define ump unordered_map
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) (ll)x.size()
#define ff first
#define ss second
#define I(a) for(auto &x:a) cin>>x;
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e5 + 5;
void solve()
{
	unsigned ll a;
	cin>>a;
	ll b[3]={0},sum=0,dig=0;
	while(a)
	{
		ll c=a%10;
		
		sum+=(c);
		sum%=3;
		b[c%3]++,dig++;
		a/=10;
	}
	if(sum==0)
	cout<<0;
	else if(sum==1)
	{
		if(b[1]&&dig>1)
		cout<<1;
		else if(b[2]>1&&dig>2)
		cout<<2;
		else
		cout<<-1;
	}
	else
	{
		if(b[2]&&dig>1)
		cout<<1;
		else if(b[1]>1&&dig>2)
		cout<<2;
		else
		cout<<-1;
	}
	
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ff first
#define ss second
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,
              tree_order_statistics_node_update>pbds;
//order_of_key:index number if it was there in sorted array
//find_by_order:value at 3rd index in sorted array.
const ll maxs=1e6+5;
ll root[maxs];

class cmp{
  bool operator()(const ll &a,const ll &b)
  {
      return a<b;
  }
};
void init()
{
    iota(root,root+maxs,0);
}
ll find(ll u)
{
    ll f;
    if(root[u]==u)
    return u;
    else
    {
        ll f=find(root[u]);
        root[u]=f;
        return f;
    }
}
void Union(ll x,ll y)
{
    ll u=find(x);
    ll v=find(y);
    root[v]=u;
}
ll power(ll x,ll y,ll p)
{
    ll res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%p;
        
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
  
ll solve(ll mid,vector<ll>&arr)
{
    ll cnt=0;
    for(auto i:arr)
    {
        if(i%mid==0)
         cnt++;
    }
    return cnt;
}
int main()
{
    ll t,n,i,k,y,x,j,a,b;
   cin>>n;
    vector<ll>arr;
    while(n>0)
    {
        ll d=n%10;
        arr.push_back(d);
        n/=10;
        
    }
    ll m=arr.size();
    ll ans=0;
    for(i=0;i<(1<<m);i++)
    {
        ll sum=0;
        for(j=0;j<m;j++)
        {
            if((1<<j)&i)
            {
                sum+=arr[j];
            }
        }
        if(sum%3==0)
        {
            ll f=__builtin_popcount(i);
            ans=max(ans,f);
        }
    }
    if(ans==0)
     cout<<-1<<endl;
     else
     {
         cout<<arr.size()-ans<<endl;
     }
   
    return 0;
    
}