#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 998244353
#define SMOD 998244353
#define ROOT 512
#define GMAX 20
#define INF 2000000000
#define EPS 0.000000001
#define NIL 0
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int prime[MAX+1],val[MAX+1];
void sieve()
{
    int i,j;
    for(i=2; i*i<=MAX; i++)
    {
        if(prime[i]) continue;
        for(j=i; j*i<=MAX; j++)
        {
            if(prime[i*j]==0) prime[i*j]=i;
        }
    }
    for(i=2;i<=MAX;i++)
    {
        if(prime[i]==0)
        {
            val[i]=1;
        }
        else
        {
            val[i]=1+val[i/prime[i]];
        }
    }
}
int main()
{
    sieve();
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        printf("%d ",val[i]+1);
    }
    return 0;
}

#include<bits/stdc++.h>
#define FastRead                      \
                                    ios_base::sync_with_stdio(false); \
                                    cin.tie(0);
#define ll long long
#define endl "\n"
#define f for
#define ml ll t,g; cin>>t; f(g=0;g<t;g++)
#define pi acos(-1)
using namespace std;
bool cmp(const pair<string,ll> &a,
         const pair<string,ll> &b)
{
    if(a.second!=b.second)
        return (a.second > b.second);
    else
        return (a.first < b.first);
}
int main()
{
    FastRead
    ll n,i,m,s=0,c=0;
    string a;
    cin>>a;
    f(i=0; i<a.size(); i++)
    {
        s=s+((ll)a[i]-48);
    }
    if(s%3==0)
        cout<<"0";
    else
    {
        f(i=0; i<a.size(); i++)
        {
            if((s-((ll)a[i]-48)!=0)&&(s-((ll)a[i]-48))%3==0)
            {
                c=1;
                break;
            }

        }
        if(c>0)
            cout<<"1";
        else if(a.size()==1 || a.size()==2)
            cout<<"-1";
        else
            cout<<"2";

    }


    return 0;
}


