import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools S = read().rstrip().decode() ques = S.count('?') def solve(a, b, c, d, e): stack = ['I'] * e + ['O'] * d + ['R'] * c + ['U'] * b + ['K'] * a K = 0 KU = 0 KUR = 0 KURO = 0 KUROI = 0 for i, x in enumerate(S): if x == '?': x = stack.pop() if x == 'K': K += 1 elif x == 'U' and K: K -= 1 KU += 1 elif x == 'R' and KU: KU -= 1 KUR += 1 elif x == 'O' and KUR: KUR -= 1 KURO += 1 elif x == 'I' and KURO: KURO -= 1 KUROI += 1 return KUROI answer = 0 for a, b, c, d in itertools.product(range(21), repeat=4): e = ques - (a + b + c + d) if e < 0: continue x = solve(a, b, c, d, e) if answer < x: answer = x print(answer)