#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int mn1 = 0, mx1 = 0, mn2 = 0, mx2 = 0;
int x[maxn], ty[maxn], n, L, R, last;
long long ans;
char op[5];
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%d%s", &x[i], &op);
    if (op[0] == 'B')
      ty[i] = 1;
    else if (op[0] == 'R')
      ty[i] = 2;
    if (!ty[i]) {
      if (!L) L = i;
      R = i;
    }
  }
  for (int i = (1); i <= (n); i++)
    if (ty[i] == 1) {
      if (!mn1) mn1 = i;
      mx1 = i;
    } else {
      if (!mn2) mn2 = i;
      mx2 = i;
    }
  if (!L) {
    ans += x[mx1] - x[mn1];
    ans += x[mx2] - x[mn2];
    cout << ans << endl;
    return 0;
  }
  ans = x[R] - x[L];
  if (mn1 && mn1 < L) ans += x[L] - x[mn1];
  if (mx1 && R < mx1) ans += x[mx1] - x[R];
  if (mn2 && mn2 < L) ans += x[L] - x[mn2];
  if (mx2 && R < mx2) ans += x[mx2] - x[R];
  for (int i = (1); i <= (n); i++)
    if (!ty[i]) {
      if (last) {
        int last1 = last, last2 = last;
        int mx1 = 0, mx2 = 0;
        for (int k = (last + 1); k <= (i - 1); k++)
          if (ty[k] == 1) {
            if (last1) mx1 = max(mx1, x[k] - x[last1]);
            last1 = k;
          } else {
            if (last2) mx2 = max(mx2, x[k] - x[last2]);
            last2 = k;
          }
        if (last1 != last) mx1 = max(mx1, x[i] - x[last1]);
        if (last2 != last) mx2 = max(mx2, x[i] - x[last2]);
        ans += min(1LL * x[i] - x[last],
                   1LL * (last1 != last ? x[i] - x[last] - mx1 : 0) +
                       1LL * (last2 != last ? x[i] - x[last] - mx2 : 0));
      }
      last = i;
    }
  cout << ans << endl;
  return 0;
}
