#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 3000000000000001 // 3e15
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fill(a, n, x) for(int i = 0; i < n; i++) a[i] = x;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 10000110;
const ll M = log2(N) + 1;

struct point
{
    ll x, y;
};

template<typename T>
T fast_exp(T x,T n)
{
    if(n == 0) return 1;
    T ans = 1;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         ans = ans * ans % mod;
    }
    else ans = fast_exp(x, n - 1) * x % mod;
    return ans;
}

void update(ll BIT[], ll i, ll x, ll n)
{
    if(i <= 0) return;
    for(; i <= n; i += i & (-i))
        BIT[i] += x;
}

ll query(ll BIT[], ll l, ll r)
{
    l--;
    ll sum = 0;
    while(r > 0)
    {
        sum += BIT[r];
        r = r & (r - 1);
    }
    while(l > 0)
    {
        sum -= BIT[l];
        l = l & (l - 1);
    }
    return sum;
}

ll fact[2], infact[2];
void work()
{
    fact[0] = fact[1] = infact[0] = infact[1] = 1;
    for(ll i = 2; i < N; i++)
    {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] = fast_exp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    if(r > n || r < 0) return 0;
    return fact[n] * infact[n - r] % mod * infact[r] % mod;
}

int main()
{
    fast;
    int _ = 1, test = 0;
   // cin >> _;
    while(_--)
    {
        test++;
        ll n, m, x = 0, y = 0, ans = 0, k = 0;
        cin >> n;
        ll a[n + 1];
        for(int i = 1; i <= n; i++) a[i] = 2;
        a[1] = 1;
        for(int i = 2; i <= n; i++)
        {
            x = a[i];
            for(int j = i + i; j <= n; j += i)
            {
                a[j] = x + 1;
            }
        }
        for(int i = 1; i <= n; i++) cout << a[i] << " ";
        //cout << ans << "\n";
    }
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll n;
  cin >> n;
  vector<int> v;
  while (n) {
    v.push_back(n % 10);
    n /= 10;
  }
  reverse(v.begin(), v.end());
  int m = v.size();
  int ans = 1e9;
  for (int bit = 1; bit < (1 << m); ++bit) {
    ll sum = 0;
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
      if (bit >> i & 1) {
        cnt++;
        sum *= 10;
        sum += v[i];
      }
    }
    if (sum % 3 == 0) {
      ans = min(ans, m - cnt);
    }
  }
  cout << (ans == 1e9 ? -1 : ans) << endl;
  return 0;
}