#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;

char s[N];

int main(){
    scanf("%s", s + 1);
    int len = strlen(s + 1);    
    bool ok = 1;
    for(int i = 1; i <= len; i += 2) if(!(s[i] >= 'a' && s[i] <= 'z'))  ok = 0;
    for(int i = 2; i <= len; i += 2) if(!(s[i] >= 'A' && s[i] <= 'Z'))  ok = 0;
    puts(ok ? "Yes" : "No"); 
}
#include <bits/stdc++.h>
        #include <math.h>
    
        using namespace std;
        typedef long long ll;
        typedef unsigned long long ull;
        # define M_PI  3.14159265358979323846
    
    
        const int M=998244353;
        long long mod(long long x){
            return ((x%M + M)%M);
        }
        long long add(long long a, long long b){
            return mod(mod(a)+mod(b));
        }
        long long mul(long long a, long long b){
            return mod(mod(a)*mod(b));
        }
    
        ll modPow(ll a, ll b){
            if(b==0)
                return 1LL;
            if(b==1)
                return a%M;
            ll res=1;
            while(b){
                if(b%2==1)
                    res=mul(res,a);
                a=mul(a,a);
                b=b/2;
            }
            return res;
        }
    

        void solve(){
            string s;
            cin>>s;
            int nb=0;
            int cnt[3]={0};
            int sum=0;
            int n=s.size();
            for(int i=0;i<n;i++){
                int k=s[i]-'0';
                cnt[k%3]++;
                sum+=k;
            }
            sum=sum%3;
            if(sum==0){
                cout<<0;
                return;
            }
            else if(sum==1){
                if(cnt[1]>0 && n>1) cout<<1;
                else if(cnt[2]>1 && n>2) cout<<2;
                else cout<<-1;
            }
            else{
                if(cnt[2]>0 && n>1) cout<<1;
                else if(cnt[1]>1 && n>2) cout<<2;
                else cout<<-1;
            }
        }
        int main(){
            ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            cout<<fixed;
            cout<<setprecision(10);
    //        freopen("timber_input.txt", "r", stdin);
    //        freopen("timber_output.txt", "w", stdout);
            int t=1;
            // cin>>t;
            for(int i=1;i<=t;i++){
            //    cout<<"Case #"<<i<<": ";
                solve();
            }
            return 0;
        }