//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  string n;
  cin >> n;
  int k = n.size();
  int mincnt = k + 1;
  rep(i, pow(2, k)) {
    string result;
    for(int tmp = 1, index = 0; index < k; tmp = tmp << 1, index++) {
      if (i & tmp) {
        result.push_back(n[index]);
      }
    }
    if (result.size() == 0) continue;
    ll tmp = stoll(result);
    if (tmp % 3 == 0) {
      int cnt = k - result.size();
      mincnt = min(mincnt, cnt);
    }
  }
  mincnt = mincnt == k + 1 ? -1 : mincnt;
  cout << mincnt << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, rem[20], len, num, ans;
bool fla[20], fla1;
vector<int> v;
inline LL read() {
	LL x = 0;
	bool f = 0;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')
			f = 1;
		c = getchar();
	}
	while (c <= '9' && c >= '0') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	if (f)
		return ~(x - 1);
	return x;
}
inline void work(int x, int m) {
	if (fla1)
		return;
	if (v.size() > m || v.size() + (len - x + 1) < m)
		return;
	if (x == len + 1) {
		int sum = 0;
		for (register int i = 1; i <= len; i++)
			if (!fla[i])
				sum += rem[i];
		if (sum % 3 == 0 && sum != 0) {
			printf("%d\n", m);
			fla1 = 1;
			return;
		}
	}
	v.push_back(x);
	fla[x] = 1;
	work(x + 1, m);
	v.pop_back();
	fla[x] = 0;
	work(x + 1, m);
}
int main() {
//	freopen ("test.in", "r", stdin);
//	freopen ("test.out", "r", stdin);
	n = read();
	if (n % 3 == 0) {
		puts("0");
		return 0;
	}
	LL n1 = n;
	while (n1) {
		rem[++len] = n1 % 10;
		n1 /= 10;
	}
	for (register int i = 1; i <= len; i++) {
		work(1, i);
		if (fla1)
			return 0;
	}
	puts("-1");
	return 0;
}
