#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;


int main()
{
    ll n,i,j,k;
    ll a=0,b=0,c=0;
    ll ci=0;
    ll cs=0;
    scanf("%lld",&n);
    while(n)
    {
        k=n%10;
        ci+=k;
        cs++;
        if(k%3==0)
            a++;
        if(k%3==1)
            b++;
        if(k%3==2)
            c++;
        n/=10;
    }
    //printf("%lld\n",cs);
    if(ci%3==0)
        printf("0\n");
    else if(ci%3==1)
    {
        if(b>0)
        {
            cs--;
            if(cs)
                printf("1\n");
            else
                printf("-1\n");
        }
        else if(c>1)
        {
            cs-=2;
            if(cs)
                printf("2\n");
            else
                printf("-1\n");
        }
        else
            printf("-1\n");
    }
    else
    {
        if(c>0)
        {
            cs--;
            if(cs)
                printf("1\n");
            else
                printf("-1\n");
        }
        else if(b>1)
        {
            cs-=2;
            if(cs)
                printf("2\n");
            else
                printf("-1\n");
        }
        else
            printf("-1\n");
    }
    return 0;
}

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;



int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
    freopen("in.txt", "rt", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int cnt = 0;
    int num;
    cin>>num;
    while (true){
        if(num%100==0&&cnt!=0){
            break;
        }
        cnt++;
        num++;
    }
    cout<<cnt<<endl;
}