#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int mnb = INT_MAX, mxb = -mnb, mna = mnb, mxa = mxb, lp = mxb, mn = mnb,
      mx = mxb, ba = 0, bb = 0, aa = 0, ab = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    char s[100];
    scanf("%d%s", &x, s);
    mn = min(mn, x);
    mx = max(mx, x);
    if (s[0] == 'R') {
      if (lp != -INT_MAX) aa = max(aa, x - max(lp, mxa));
      mxa = max(mxa, x);
      mna = min(mna, x);
      ba = 1;
    } else if (s[0] == 'B') {
      if (lp != -INT_MAX) ab = max(ab, x - max(lp, mxb));
      mxb = max(mxb, x);
      mnb = min(mnb, x);
      bb = 1;
    } else {
      if (lp == -INT_MAX) {
        if (mxa != -INT_MAX) ans += x - mna;
        if (mxb != -INT_MAX) ans += x - mnb;
      } else {
        long long res = 0;
        ans += x - lp;
        aa = max(aa, x - mxa);
        ab = max(ab, x - mxb);
        if (mxa != -INT_MAX) res += x - lp - aa;
        if (mxb != -INT_MAX) res += x - lp - ab;
        res = min(res, (long long)x - lp);
        ans += res;
      }
      mnb = INT_MAX, mxb = -mnb, mna = mnb, mxa = mxb, aa = 0, ab = 0;
      lp = x;
    }
  }
  if (lp != -INT_MAX && mxa != -INT_MAX) ans += mxa - lp;
  if (lp != -INT_MAX && mxb != -INT_MAX) ans += mxb - lp;
  if (lp == -INT_MAX && mxa != -INT_MAX) ans += mxa - mna;
  if (lp == -INT_MAX && mxb != -INT_MAX) ans += mxb - mnb;
  printf("%lld\n", ans);
}
