#include #include #include #include #include #include #include #include #include #include #include #include #include #define p(s) cout<<(s)<=n;i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define F first #define S second typedef long long ll; using namespace std; const ll inf=1e9+7; string n; int a[] ={1,0,0,0,1,0,1,0,2,1}; int main(){ cin>>n; int h=0; REP(i,0,n.size()){ h += a[n[i]-'0']; } p(min(2*n.size()+ h+1, 2*(h+1)+n.size())); return 0; }