#include using namespace std; //const double PI = acos(-1); using ll = long long; using ull = unsigned long long; const int inf = 2e9; const ll INF = 4e18; const ll MOD = 1e9+7; int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int ans = 0; if (s[0] != '1') { cout << -1 << endl; return 0; } for (int i = 1; i < s.size(); i++) { if (s[i] == '3') ans++; else { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }