//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber
 
#include <bits/stdc++.h>
 
using namespace std;
 
// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
 
// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
 
// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
 
// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};
 
// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
 
// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;
 
    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }
 
    return ans;
}


ll ans = 0;
vi ara;
void solve(ll i, ll num, ll cnt)
{
	if(num%3==0){
		ans = max(ans, cnt);
	}
	if(i==sz(ara)) return;
	
	solve(i+1, num*10+ara[i], cnt+1);
	solve(i+1, num, cnt);
}
void task()
{
	// Code here...
	
	ll n;
	
	cin >> n;
	
	while(n){
		ara.PB(n%10);
		n /= 10;
	}
	reverse(all(ara));
	
	solve(0, 0, 0);
	
	if(0==ans) cout << "-1\n";
	else cout << sz(ara)-ans << "\n";
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	
	task();
 
    return 0;
}

// #pragma GCC optimise ("O1")
#include<bits/stdc++.h>
using namespace std;
#define ll           int
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define _rep(i,n)   for(ll i=n-1;i>=1;i--)
#define scn(a)       scanf("%lld",&a)
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define vec          vector<ll>
#define pb           push_back    
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define read(a)       for(auto &it:a) cin>>it;
#define write(a)      for(auto it:a) cout<<it<<" ";
#define yeS(GOOD)      GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define mem(a,b)     memset(a,b,sizeof(a))
#define nl           printf("\n")
#define inf          1e9
#define zer          INT_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N=20000;
long long n;
vec v;
ll dp[20][20][N],k;
ll f(ll i, ll j, ll sum=0)
{
// cout<<sum<<endl;
	if(i==(int)v.size() && j<=k-1)
	{
		// cout<<sum<<endl;
		if(sum%3==0 && sum)
		return 0;
		
		return 1e9;
	}
	
	if(i==(int)v.size() || j>k-1)
	return 1e9;

	if(dp[i][j][sum]!=-1)
	return dp[i][j][sum];
	
	ll ans=0;
	
	ans=min(f(i+1,j+1,sum)+1,f(i+1,j,sum+v[i]));
	
	return dp[i][j][sum]=ans;
	
}

void solve()
{
	cin>>n;
	// cout<<n<<endl;
	
	v.clear();
	mem(dp,-1);
	while(n)
	{
		int dig=(int)(n%10);
		v.pb(dig);
		n/=10;
		k++;
	}

	ll ans=f(0,0);
	if(ans>=1e9) ans=-1;
	cout<<ans<<endl;
}

int main()
{
	  int queries=1; 
	  // cin>>queries;
	  while(queries--)
	  {
	    solve();
	  }
}