#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; void solve() { string s; cin >> s; smatch m; regex_search(s, m, regex("(^13*)")); cout << ((s.size() > 1 && s.size() == m.length()) ? m.length() - 1 : -1) << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); getchar(); }