import sys sys.setrecursionlimit(10 ** 6) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() nsa = lambda: list(map(str, stdin.readline().split())) ntp = lambda: tuple(map(int, stdin.readline().split())) mod = 10 * 9 + 7 inf = 2 << 90 S = list(ns()) n = len(S) n1 = ('0', '4', '6', '9') n2 = ('8') ans1 = n * 2 + 1 for s in S: if s in n1: ans1 += 1 if s in n2: ans1 += 2 ans2 = n + 2 for s in S: if s in n1: ans2 += 2 if s in n2: ans2 += 4 print(min(ans1, ans2))