#include #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; using namespace std; const int INF = 1e9; int main() { string s; cin >> s; int cnt = 0; for (int i = 1; i < s.size(); ++i) { if (s[i] != '3') { cout << -1 << endl; return 0; } else ++cnt; } if (s.size() >= 2 && s[0] == '1') cout << cnt << endl; else cout << -1 << endl; return 0; }