#include using namespace std; int main() { string S; cin >> S; int ans = 0; for (int i = 1; i < S.size(); i++) { if (S.at(i) == '3') ans++; else { ans = -1; break; } } cout << ((S.at(0) == '1' && ans) ? ans : -1) << "\n"; }