#include #include #include using namespace std; int main() { string S; cin >> S; bool ok = S[0] == '1'; int n = S.length(); int cnt3 = count(S.begin() + 1, S.end(), '3'); ok &= cnt3 == n - 1 && cnt3 > 0; if (ok) { cout << cnt3 << endl; } else { cout << -1 << endl; } return 0; }