#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int gcd(int m,int n) { // 引数に0がある場合は0を返す if ( ( 0 == m ) || ( 0 == n ) ) return 0; // ユークリッドの方法 while( m != n ) { if ( m > n ) m = m - n; else n = n - m; } return m; }//gcd int main(){ // input ll N; cin >>N; //vector v(N); //std::sort(g.begin(),g.end()); ll ans = 0; ll out = -1; int flag = 1; while(flag != 0){ N = N-3; if(N % 10 == 0){ N = N /10; ans++; }else{ flag = 0; out = -1; } if( N==1){ flag =0; out = ans; } if(N<=0){ out = -1; flag = 0; } } cout << out << endl; return 0; }