#include<iostream>
#include<string>
using namespace std;

string judge(long N) {
	if (N == 0) return "Yes";
	while (N % 10 == 0) {
		N /= 10;
	}
	long reverse = 0;
	long  buf = N;
	while (buf != 0) {
		reverse = reverse * 10 + buf % 10;
		buf /= 10;
	}
	if (N == reverse) return "Yes";
	else return "No";
}

int main() {

	long N = 0;
	cin >> N;

	cout << judge(N) << endl;

}
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;

void solve();

int main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
}

#define int long long

const int N = 2e5 + 100, mod = 1e9 + 7, INF = 2e18;
long double EPS = 0.00000001;

bool bit(int a, int n) {
    return (a >> n) & 1;
}

string s;
int ans = 0;

void solve() {
    cin >> s;
    for (int mask = 0; mask < (1 << s.size()); mask++) {
        int k = 0, cnt = 0;
        for (int i = 0; i < s.size(); i++) {
            if (bit(mask, i)) {
                k += s[i] - '0';
                cnt++;
            }
        }
        if (k % 3 == 0) {
            ans = max(ans, cnt);
        }
    }
    if (ans == 0) cout << -1;
    else cout << s.size() - ans;
}