#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

signed main()
{
    

    int a[3];
    mem(a,0);

    int n;
    cin>>n;

    int l=0;

    int sum=0;

    while(n>0)
    {
        int x=n%10;
        n=n/10;
        a[x%3]++;
        sum+=x;
        l++;
    }

    sum=sum%3;
    if(!sum)
    {
        cout<<"0\n";
    }
    else if(sum==1)
    {
        if(a[1]&&l>1) cout<<"1\n";
        else if(a[2]>=2&&l>2) cout<<"2\n";
        else cout<<"-1\n";
    }
    else
    {
        if(a[2]&&l>1) cout<<"1\n";
        else if(a[1]>=2&&l>2) cout<<"2\n";
        else cout<<"-1\n";
    }
    
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iil pair<ll,ll>
#define se second
#define ld long double
#define mod 0
#define popcount __builtin_popcountll
#define x0 zxcxzcsacasd
#define x1 ghfghujfgfg
#define y0 olkjhdnncvcv
#define y1 bhvgrewm345345435
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
#define all(x) x.begin(), x.end()
using namespace std;
ll l;
ll dp[222][15];
ll cal(int i, int c){
	if(i == l)return 0;
	if(c == 11)return 1;
	ll &ret = dp[i][c];
	if(ret!=-1)return ret;
	ret = 0;
	ret  = cal(i + 1, c);
	ret += cal(i + 1, c + 1);
	return ret;
}
void test_case(){
	cin>>l;
	memset(dp, -1, sizeof dp);
	cout<<cal(0, 0)<<endl;
}
int main(){
	int t = 1;
	// scanf("%d", &t);
	while(t--)test_case();
}
