#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> byteland, berland;
  long long ans = 0;
  bool flag = false;
  for (int i = 1, x; i <= n; i++) {
    char s[5];
    scanf("%d %s", &x, s);
    if (s[0] == 'B')
      byteland.push_back(x);
    else if (s[0] == 'R')
      berland.push_back(x);
    else {
      byteland.push_back(x);
      berland.push_back(x);
      if (!flag) {
        ans += x - byteland[0];
        ans += x - berland[0];
      } else {
        long long add = (long long)(x - byteland[0]) * 2LL;
        long long res1 = 0;
        for (int j = 0; j + 1 < byteland.size(); j++)
          res1 = max((int)res1, byteland[j + 1] - byteland[j]);
        res1 = x - byteland[0] - res1;
        long long res2 = 0;
        for (int j = 0; j + 1 < berland.size(); j++)
          res2 = max((int)res2, berland[j + 1] - berland[j]);
        res2 = x - berland[0] - res2;
        ans += min(add, res1 + res2 + x - byteland[0]);
      }
      flag = true;
      byteland.clear();
      berland.clear();
      byteland.push_back(x);
      berland.push_back(x);
    }
  }
  if (byteland.size()) ans += byteland[byteland.size() - 1] - byteland[0];
  if (berland.size()) ans += berland[berland.size() - 1] - berland[0];
  printf("%lld\n", ans);
  return 0;
}
