n = input() N = len(n) NH = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1] tmp = 1 for s in n: tmp += NH[int(s)] print(min(tmp * 2 + N, 2 * N + tmp))