//https://atcoder.jp/contests/abc182/tasks/abc182_c
//C - To 3
#include <bits/stdc++.h>

using namespace std;

int main() {
    long long n;
    cin>>n;

    //特判
    if (0==n%3) {
        cout<<"0\n";
        return 0;
    } else if (n<=2) {
        cout<<"-1\n";
        return 0;
    }

    //转换为数字
    int cnt[3]={};//每个数字个数
    int tot=0;//每个位数总和
    vector<int> v;
    while (n) {
        int p=n%10;//取个位
        n/=10;
        tot+=p;
        v.push_back(p);
        cnt[p%3]++;
    }

    n = v.size();
    if (1==tot%3) {
        if (n>1 && cnt[1]>=1) {
            cout<<"1\n";
        } else if (n>2 && cnt[2]>=2) {
            cout<<"2\n";
        } else {
            cout<<"-1\n";
        }
    } else if (2==tot%3) {
        if (n>1 && cnt[2]>=1) {
            cout<<"1\n";
        } else if (n>2 && cnt[1]>=2) {
            cout<<"2\n";
        } else {
            cout<<"-1\n";
        }
    }

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    string s;
    cin >> s;
    int right = s.length()-1;
    while (s[right] == '0') {
        right--;
    }
 
    for (int left = 0; right >= 0; ++left) {
        if (s[left] != s[right]) {
            cout << "No";
            return 0;
        }
        --right;
    }
 
    cout << "Yes";
    return 0;
}

//je kotinnnnnnnnnnnnnnnn