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 x in 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, e, b, c in itertools.product(range(21), range(21), range(101), range(101)): d = ques - (a + b + c + e) if d < 0: continue x = solve(a, b, c, d, e) if answer < x: answer = x print(answer)