#include using namespace std; typedef long long ll; typedef pair P; const int INF = 1e9; const int mod = 1e9+7; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { string s; cin >> s; int flag = 0,cnt = 0; if(s[0] != '1') flag = 1; for(int i = 1; i < s.size(); i++){ if(s[i] == '3') cnt++; else flag = 1; } cout << (flag ? -1 : cnt) << endl; return 0; }