import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def solve(T):
ans = 0
n, q, next_c = 0, 0, 0
for i, t in enumerate(T):
if t == "2":
if next_c == 0:
n += 1
else:
n = 1
if q > 0:
n += q - (q % 2 != 0)
q = 0
next_c = 1
elif t == "5":
if next_c == 1:
n += 1
else:
if q > 0:
n = 1 + q - (q % 2 == 0)
else:
n = 0
q = 0
next_c = 0
elif t == "?":
q += 1
n += 1
else:
n, q, next_c = 0, 0, 0
if n % 2 == 0:
ans = max(ans, n)
return ans
def main():
T = input()
print(solve(T))
if __name__ == '__main__':
main()