#!/usr/bin/perl -w

use strict;
use v5.30;

my @dir = ([0, -1], [1, 0], [0, 1], [-1, 0]);
my $d = 0;

my ($x, $y) = (0, 0);

$_ = <>;
while (/([LR])(\d+)/g) {
	if ($1 eq 'L') {
		$d = $#dir if --$d < 0;
	} else {
		$d = 0 if ++$d > $#dir;
	}
	$x += $2 * $dir[$d]->[0];
	$y += $2 * $dir[$d]->[1];
}

say abs($x)+abs($y);
	
