import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = [int(x) - ord('0') for x in read().rstrip()] G = [1,0,0,0,1,0,1,0,2,1] nums = len(N) holes = sum(G[n] for n in N) a,b = nums, holes + 1 answer = min(a+a+b, b+b+a) print(answer)