#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 100010;
int n;
int main()
{
map<int, int> b;
cin >> n;
int x = 0;
while (n -- )
{
int y;
char c;
cin >> y >> c;
if (c == 'R')
{
b[x] ++ ;
b[x + y] -- ;
x += y;
}
else
{
b[x - y] ++ ;
b[x] -- ;
x -= y;
}
}
int res = 0, sum = 0, last;
for (auto [x, v]: b)
{
if (sum >= 2)
res += x - last;
sum += v;
last = x;
}
cout << res << endl;
return 0;
}