def main(): N = list(input()) count = 0 for n in N: if n in ("1","2","3","5","7"): count += 0 elif n in ("0","4","6","9"): count += 1 elif n == "8": count += 2 count += 1 + 2*len(N) count2 = 1 for n in N: if n in ("1","2","3","5","7"): count2 += 0 elif n in ("0","4","6","9"): count2 += 1 elif n == "8": count2 += 2 count2 = count2*2 + len(N) print(min(count, count2)) if __name__ == "__main__": main()