package yukicoder; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public class No509 { char[] nC; HashSet more1 = new HashSet<>(); public static void main(String[] args) { No509 main = new No509(); main.run(); } private void run() { String n = new Scanner(System.in).next(); nC = n.toCharArray(); more1.addAll(Arrays.asList('0', '4', '6', '9')); int res, res2; if((res= p1()) < (res2 = p2())) { System.out.println(res); } else { System.out.println(res2); } } private int p1() { int cnt = nC.length + 1; for(char each : nC) { if( more1.contains(each) ) cnt++; if(each == '8') cnt += 2; } return cnt + nC.length; } private int p2() { int cnt = 1; for(char each : nC) { if( more1.contains(each) ) cnt++; if(each == '8') cnt += 2; } cnt += nC.length + 1; for(char each : nC) { if( more1.contains(each) ) cnt++; if(each == '8') cnt += 2; } return cnt; } }