#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;



int main() {

    string S; cin >> S;
    int k = S.size();
    int ans = INF;
    for (int bit = 0; bit < (1<<k); ++bit) {
        int sum = 0;
        int ans_tmp = 0;
        for (int i=0; i < k; ++i) {
            if (bit & (1<<i)) {
                ans_tmp++;
            } else {
                sum += S[i] - '0';
            }
        }
        if (sum > 0 && sum % 3 == 0) ans = min(ans, ans_tmp);
    }

    if (ans == INF) ans = -1;
    out(ans);
    

    return 0;
}




#include <iostream>
#include <vector>
using namespace std;
int n, ans = -1;
vector<int> nums, lst;

void dfs(int pos, int s) {
    if (pos == n) {
        if (lst.size() > 0 && s % 3 == 0) ans = max(ans, (int)lst.size());
        return ;
    }
    lst.push_back(nums[pos]);
    dfs(pos + 1, s + nums[pos]);
    lst.pop_back();
    dfs(pos + 1, s);
}

int main() {
    long long tmp;
    cin >> tmp;
    while (tmp) {
        nums.push_back(tmp % 10);
        tmp /= 10;
    }
    n = nums.size();
    dfs(0, 0);
    if (ans == -1) cout << -1 << endl;
    else cout << (int)nums.size() - ans << endl;
    return 0;
}