#include using namespace std; bool ok (const string &s) { const int n = s.length(); bool ret = (s[0] == '1' and n > 1); for (int i = 1; i < n; i++) ret &= (s[i] == '3'); return ret; } int main() { string s; cin >> s; if (not ok(s)) cout << -1 << endl; else cout << count_if(s.begin(),s.end(),[](char c){return (c=='3');}) << endl; return 0; }