#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define MOD 1000000007
#define foru(i,a,b) for(int i=(a); i<(b); i++)
#define forue(i,a,b) for(int i=(a); i<=(b); i++)
#define forb(i,n) for(int i=n-1; i>=0; i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
#define pt(x) cout << x << "\n"
#define sz(c) ((int)c.size())
#define add(a, b, w) edges[a].pb(make_pair(b, w))
typedef pair<int,int> ii;
typedef long long int ll;

string s;
int l;
int dp[20][200];

int solve(int i, int sum){
    if(!sum) return INF;
    else if(!(sum%3)) return 0;
    if(i>=l) return INF;
    else if(dp[i][sum]) return dp[i][sum];

    int r1 = 1 + solve(i+1,sum-(s[i]-'0'));
    int r2 = solve(i+1,sum);
    return dp[i][sum] = min(r1,r2);
}


int main(){

    //freopen("input.in", "r", stdin);
    //cin.tie(0);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> s;
    int actualSum = 0;
    l = s.size();
    foru(i,0,l){
        actualSum += s[i] - '0';
    }
    int r = solve(0,actualSum);
    if(r == INF) pt(-1);
    else pt(r);
}
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a;
    cin >> a;
    int sum = 0;
    bool mod1 = false, mod2 = false, mod0 = false;
    int d = 0;
    while (a) {
        d++;
        int t = a % 10;
        sum += t;
        if (t % 3 == 1) {
            mod1 = true;
        }
        if (t % 3 == 2) {
            mod2 = true;
        }
        if (t % 3 == 0) {
            mod0 = true;
        }
        a = a / 10;
    }
    if (d < 3 && sum % 3 != 0 && !mod0) {
        cout << -1 << endl;
        return 0;
    }
    if (sum % 3 == 0) {
        cout << 0 << endl;
    } else if (sum % 3 == 1) {
        if (mod1) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    } else {
        if (mod2) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    }
    return 0;
}