#include using namespace std; int main() { string S; cin >> S; regex R ("13+"); cout << ((regex_match(S, R)) ? (int) S.size() - 1 : -1) << "\n"; }