import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] num = new int[10]; int r = 0; for(int i = 0; i < 10; i++) { int d = n % 10; num[d]++; r++; n /= 10; if(n == 0) break; } int ana = 0; for(int i = 0; i < 10; i++) { if((i == 0) || (i == 4) || (i == 6) || (i == 9)) ana += (num[i]); if(i == 8) ana += (2 * num[i]); } int ans1 = 2 * r + 1 + ana; int ans2 = r + (2 * ana) + 2; int ans = Math.min(ans1, ans2); System.out.println(ans); } }