import java.util.Scanner; public class Nuritsubushi { public static void main(String[] args) { Scanner s = new Scanner(System.in); StringBuilder n = new StringBuilder(s.next()); s.close(); int a = 0,b = 0,c = 0,count = 0; while(n.length() != 0){ char ch = n.charAt(0); n.deleteCharAt(0); if(ch == '8'){ c++; }else if(ch == '0' || ch == '4' || ch == '6' || ch == '9'){ b++; }else{ a++; } } count = a*2 + b*3 + c*4 + 1; count = Math.min(count, a + b*3 + c*5 + 2); System.out.println(count); } }