#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main() {
	int64_t n;
	scanf("%" SCNd64, &n);
	
	int cnt[3] = { 0 };
	while (n) {
		cnt[n % 10 % 3]++;
		n /= 10;
	}
	int cur = (cnt[1] + 2 * cnt[2]) % 3;
	int k = cnt[0] + cnt[1] + cnt[2];
	int res;
	if (!cur) res = 0;
	else if (cur == 1) {
		if (cnt[1]) {
			if (k == 1) res = -1;
			else res = 1;
		} else {
			if (k == 2) res = -1;
			else res = 2;
		}
	} else {
		if (cnt[2]) {
			if (k == 1) res = -1;
			else res = 1;
		} else {
			if (k == 2) res = -1;
			else res = 2;
		}
	}
	printf("%d\n", res);
	
	return 0;
}
 

#include <bits/stdc++.h>
// #include <atcoder/all>
#include <cmath>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INFI = 1001001001;
const ll INFL = 1001001001001001001;
const ll MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, in, fn) for (ll i = in; i <= fn; i++)
#define debug(x) cerr << #x << ": " << x << endl

void solve(std::string S)
{
    ll ans = 0;
    rep(i, 12)
    {

        if (S[i] == 'Z' && S[i + 1] == 'O' && S[i + 2] == 'N' && S[i + 3] == 'e')
            ans++;
    }
    cout << ans << endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}
