#include using namespace std; const set ST = {0, 4, 6, 9}; int main() { string n; cin >> n; int sz = n.size(); int res1 = 2 * sz + 1; for (int i = 0; i < sz; i++) { int cd = n[i] - '0'; if (ST.count(cd)) res1++; else if (cd == 8) res1 += 2; } int res2 = sz + 2; for (int i = 0; i < sz; i++) { int cd = n[i] - '0'; if (ST.count(cd)) res2 += 2; else if (cd == 8) res2 += 4; } cout << min(res1, res2) << endl; return (0); }