#include "bits/stdc++.h" using namespace std; int main() { string S; bool check = true; cin >> S; if (S == "1") { cout << -1 << endl; return 0; } if (S[0] != '1') check = false; for (int i = 1; i < S.size(); i++) { if (S[i] != '3') check = false; } if (check) cout << S.size() - 1 << endl; else cout << -1 << endl; }