import Data.List.Split
import qualified Data.Map as Map

data Direction
  = N
  | E
  | S
  | W
  deriving (Show, Ord, Eq)

turnMap =
  Map.fromList $
  [ ((dirs !! i, 'L'), dirs !! ((i - 1) `mod` 4))
  | i <- [0 .. 3] ] ++
  [ ((dirs !! i, 'R'), dirs !! ((i + 1) `mod` 4))
  | i <- [0 .. 3] ]
  where
    dirs = [N, E, S, W]

move facing x y [] = (x, y)
move facing x y ((turn, numSteps):ss)
  | facing' == N = move facing' (x + numSteps) y ss
  | facing' == S = move facing' (x - numSteps) y ss
  | facing' == E = move facing' x (y + numSteps) ss
  | facing' == W = move facing' x (y - numSteps) ss
  where
    facing' = turnMap Map.! (facing, turn)

parseStep :: String -> (Char, Integer)
parseStep (turn:numSteps) = (turn, read numSteps)

main = do
  line <- getLine
  let steps = map parseStep $ splitOn ", " line
  let (x, y) = move N 0 0 steps
  print $ abs x + abs y
