#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,N) for (int i = 0; i < (N); i++) using ll = long long; using lb = long double; using namespace std; const int mod = 1000000007; ll nCk(ll N, ll K){ ll kid = 1; for(ll i = N; i > N - K; i--){ kid = kid * i; } for(ll i = 1; i < K + 1; i++){ kid = kid / i; } return kid; } ll gcd(ll P, ll Q){ return Q ? gcd(Q,P % Q):P; } ll lcm(ll P, ll Q){ return P / gcd(P,Q) * Q; } string change_big(string str){ transform(str.begin(), str.end(), str.begin(), ::toupper); return str; } string change_small(string str){ transform(str.begin(), str.end(), str.begin(), ::tolower); return str; } bool is_prime(int x){ if(x<=1) return false; for(int i=2;i*i<=x;i++) if(x%i==0) return false; return true; } ll sum_of_num(ll num){ ll dig; ll sum = 0; while(num){ dig = num % 10; sum = sum + dig; num = num / 10; } return sum; } ll how_many_break(ll n, ll m){ ll counter = 0; while (n % m == 0){ n = n / m; counter++; } return counter; } /*------------------------------------------------------------------------------------*/ int main(){ string S; cin >> S; ll N = S.size(); ll ans = 0; if(S[0] == '1'){ ans++; } for(ll i = 1; i < N; i++){ if(S[i] == '3'){ ans++; } } if(ans == N){ cout << ans - 1 << endl; } else{ cout << "-1" << endl; } }