#include using namespace std; using ll = long long; ll N, M, K; int main() { string s; cin >> s; for (int i = 1; i < s.size(); i++) { if (s[0] == '1' && s[i] != '3') { puts("-1"); return 0; } } cout << s.size() - 1 << endl; }