//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>
#include<fstream>
#include<array>
#include<assert.h>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	int cnt[] = { 0,0,0 };
	int tk = N;
	int sum = 0;
	int d = 0;
	while (tk > 0)
	{
		d++;
		cnt[(tk % 10) % 3]++;
		sum += tk % 10;
		tk /= 10;
	}

	sum %= 3;

	if (sum == 0)cout << 0 << endl;
	else if (sum == 1)
	{
		if (d>1&&cnt[1] > 0)cout << 1 << endl;
		else if (d>2&&cnt[2] > 1)cout << 2 << endl;
		else cout << -1 << endl;
	}
	else
	{
		if (d > 1 && cnt[2] > 0)cout << 1 << endl;
		else if (d > 2 && cnt[1] > 1)cout << 2 << endl;
		else cout << -1 << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 9;
const int mod = 1e9 + 7;

int n, res = -1;
char a[20];

void solve(int idx, int sum, int cnt) {

    if (idx == n) {
        if (sum && sum%3 == 0)
            res = max(res, cnt);
        return;
    }

    solve(idx + 1, sum + (a[idx] - '0'), cnt + 1);
    solve(idx + 1, sum, cnt);
}
int main() {

    scanf("%s",a);
    n = strlen(a);
    solve(0, 0, 0);
    printf("%d", (res == -1 ? res : n - res));
    return 0;
}
