n = input() add = 0 for c in n: if c in "4690": add += 1 elif c == "8": add += 2 print(min(2 * len(n) + 1 + add, len(n) + 2 + 2 * add))