#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2e5 + 5, INF = 0x3f3f3f3f;

int main(){
    
    ll n;
    cin >> n;
    int res = 0;
    for(int i = 1; i <= 1000000; i ++ ){
        int ans = 0, x = i;
        while(x){
            ans ++;
            x /= 10;
        }
        if(i * pow(10, ans) + i <= n)   res ++;
    }
    
    cout << res << endl;
    
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string s;
int n;

int is_ok(int i, int c, int d){
	if(i == n){
		return (c == 0) ? d : INT_MAX; 
	}

	return min(is_ok(i+1, (c+s[i]-'0')%3, d), is_ok(i+1, c, d+1));
}

signed main(){
	cin >> s;
	n = s.size();

	int ans = is_ok(0, 0, 0);

	if(ans >= n){
		ans = -1;
	}

	cout << ans << endl;

	return 0;
}
