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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	string s;
	cin >> s;
	vector <ll> dp (9*s.size()+2, -INF);
	for (i = 0; i < 1LL<<s.size(); ++i)
	{
		int cs = 0, ca = 0;
		for (j = 0; j < s.size (); ++j)
			cs += (i>>j&1)*(s[j] - '0'),
			ca += (i>>j&1);
		dp[cs] = ca;
	}
	ll ans = -1;
	for (i = 0; i < dp.size (); i += 3)
		ans = max (ans, dp[i]);
	if (ans == 0) cout << -1 << '\n';
	else cout << s.size () - ans << '\n';

	return 0;
}


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

int main() {
  
  string N;
  cin >> N;
  
  int l = N.size();
  
  int zero = 0, one = 0, two = 0;
  for (int i = 0; i < l; i++) {
    if (N[i]%3 == 1) one++;
    else if (N[i]%3 == 2) two++;
    else zero++;
  }
  
  if (one == 0 && two == 0) cout << 0 << endl;
  else if (zero == 0 && one <= 2 && two == 0) cout << -1 << endl;
  else if (two == 0) cout << one%3 << endl;
  else if (zero == 0 && one == 0 && two <= 2) cout << -1 << endl;
  else if (one == 0) cout << two%3 << endl;
  else if ((one-two)%3 == 0) cout << 0 << endl;
  else cout << 1 << endl;

return 0;
}