""" day_02_01.py """

# usage: python3 day_02_01.py < input

import sys


def wyps():
    """ yield the next waypoint """
    wps = ['r', 'o', 'y', 'g', 'b', 'v']
    while True:
        yield from wps


waypoint = wyps()

total = 0

with sys.stdin as infile:
    next(waypoint)
    while (op := infile.read(1)) and op != '\n':
        while next(waypoint) != op:
            total += 1
        total += 1

print(total)
