#include <stdio.h>

int count[10];
int main()
{
	long long int a;
	scanf("%lld",&a);
	int sum = 0,digit = 0;
	while(a)
	{
		sum += (a%10);
		digit++;
		count[(a%10)%3]++;
		a/=10;
	}
	if(sum%3==0) printf("0");
	else if(sum%3==1)
	{
		if(digit>=2&&count[1]>=1) printf("1");
		else if(digit>=3&&count[2]>=2) printf("2");
		else printf("-1");
	}
	else
	{
		if(digit>=2&&count[2]>=1) printf("1");
		else if(digit>=3&&count[1]>=2) printf("2");
		else printf("-1");
	}
}
#include <bits/stdc++.h>

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXS 100010


int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	LL n;
	cin>>n;
	
	int sum=0;
	int rem1=0;
	int rem2=0;
	int lg=0;
	while(n){
		lg++;
		int t1=(n%10)%3;
		sum+=t1;
		sum%=3;
		if(t1==1)
			rem1+=1;
		if(t1==2)
			rem2+=2;
		
		n/=10;
	}
	
	if(sum==0)
		cout<<0;
	else{
		if(lg>1&&((sum==1&&rem1>=1)||(sum==2&&rem2>=1)))
			cout<<1;
		else if(lg>2&&((sum==2&&rem1>=2)||(sum==1&&rem2>=2)))
			cout<<2;
		else
			cout<<-1;
	}
}
