import java.io.*; import java.util.*; public class Main_yukicoder509 { private static Scanner sc; private static Printer pr; private static void solve() { char[] n = sc.next().toCharArray(); int[] cnt = new int[10]; for (char c : n) { cnt[c - '0']++; } int b = 1; int o = cnt[0] + cnt[4] + cnt[6] + cnt[8] * 2 + cnt[9]; int g1 = cnt[1] + cnt[2] + cnt[3] + cnt[5] + cnt[7]; int g2 = cnt[0] + cnt[4] + cnt[6] + cnt[8] + cnt[9]; int min = Integer.MAX_VALUE; min = Math.min(min, g1 + g2 + o + b + g1 + g2); min = Math.min(min, b + o + g1 + g2 + o + b); // min = Math.min(min, g2 + o + b + g1 + g2 + b); pr.println(min); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }