#include <bits/stdc++.h>
using namespace std;
const int MAXN = -1;
struct dot {
  long long x;
  char c;
};
int n;
long long I, D;
vector<dot> P;
vector<long long> B, R;
long long solveme() {
  if (!R.size() && !B.size()) return D - I;
  long long maxr, maxb;
  if (R.size()) maxr = max(R[0] - I, D - R.back());
  for (int i = (0); i < (int)(R.size() - 1); i++)
    maxr = max(maxr, R[i + 1] - R[i]);
  if (B.size()) maxb = max(B[0] - I, D - B.back());
  for (int i = (0); i < (int)(B.size() - 1); i++)
    maxb = max(maxb, B[i + 1] - B[i]);
  if (R.size() && B.size()) {
    return min(2 * (D - I), 3 * (D - I) - (maxr + maxb));
  }
  if (B.size()) return 2 * (D - I) - maxb;
  return 2 * (D - I) - maxr;
}
void nohayG() {
  R.clear();
  B.clear();
  long long ans = 0;
  for (int i = (0); i < (int)(n); i++) {
    if (P[i].c == 'R')
      R.push_back(P[i].x);
    else
      B.push_back(P[i].x);
  }
  if (R.size()) ans += R.back() - R[0];
  if (B.size()) ans += B.back() - B[0];
  printf("%lld\n", ans);
}
int main() {
  while (cin >> n) {
    long long ans = 0;
    bool G = false;
    P.resize(n);
    for (int i = (0); i < (int)(n); i++) {
      cin >> P[i].x >> P[i].c;
      if (P[i].c == 'G') G = true;
    }
    if (!G) {
      nohayG();
      continue;
    }
    int l = 0, r = n - 1;
    R.clear();
    B.clear();
    while (P[l].c != 'G') {
      if (P[l].c == 'B')
        B.push_back(P[l].x);
      else
        R.push_back(P[l].x);
      l++;
    }
    if (R.size()) ans += P[l].x - R[0];
    R.clear();
    if (B.size()) ans += P[l].x - B[0];
    B.clear();
    while (P[r].c != 'G') {
      if (P[r].c == 'B')
        B.push_back(P[r].x);
      else
        R.push_back(P[r].x);
      r--;
    }
    if (R.size()) ans += R[0] - P[r].x;
    R.clear();
    if (B.size()) ans += B[0] - P[r].x;
    B.clear();
    I = P[l].x;
    if (r > l)
      for (int i = (l + 1); i < (int)(r + 1); i++) {
        switch (P[i].c) {
          case 'R':
            R.push_back(P[i].x);
            break;
          case 'B':
            B.push_back(P[i].x);
            break;
          case 'G': {
            D = P[i].x;
            ans = ans + solveme();
            I = D;
            R.clear();
            B.clear();
            break;
          }
        }
      }
    printf("%lld\n", ans);
  }
  return 0;
}
