#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); int res; if (s[0] != '1') res = -1; else { res = n - 1; for (int i = 1; i < n; ++i) if (s[i] != '3') res = -1; } cout << res << '\n'; }