#include <bits/stdc++.h>
using namespace std;
const int TAM = 3e6;
int n, pos[TAM];
string s[TAM];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> pos[i] >> s[i];
  int rd = 0, bd = 0, rm = 0, bm = 0, lr = 0, lb = 0, fr = INT_MAX,
      fb = INT_MAX, pg = -1, rc = 0, bc = 0, ans = 0;
  int a, b, c, ca, cb;
  for (int i = 0; i < n; i++) {
    if (s[i] == "G") {
      if (pg >= 0) {
        ca = pos[i] - pg;
        if (rc) {
          a = rd + fr - pg;
          b = rd + fr - pg + pos[i] - lr - rm;
          c = rd + pos[i] - lr;
          ca += min(a, min(b, c));
        }
        if (bc) {
          a = bd + fb - pg;
          b = bd + fb - pg + pos[i] - lb - bm;
          c = bd + pos[i] - lb;
          ca += min(a, min(b, c));
        }
        if (rc and bc)
          cb = rd + fr - pg + pos[i] - lr + bd + fb - pg + pos[i] - lb;
        else
          cb = INT_MAX;
        ans += min(ca, cb);
      } else {
        if (rc) ans += (rd + pos[i] - lr);
        if (bc) ans += (bd + pos[i] - lb);
      }
      pg = pos[i];
      rd = bd = rm = bm = lr = lb = rc = bc = 0;
      fr = fb = INT_MAX;
    } else if (s[i] == "R") {
      if (!rc)
        fr = lr = pos[i];
      else {
        rm = max(rm, pos[i] - lr);
        lr = pos[i];
      }
      rd = lr - fr;
      rc++;
    } else {
      if (!bc)
        fb = lb = pos[i];
      else {
        bm = max(bm, pos[i] - lb);
        lb = pos[i];
      }
      bd = lb - fb;
      bc++;
    }
  }
  if (s[n - 1] != "G") {
    if (pg == -1) {
      if (rc) ans += (lr - fr);
      if (bc) ans += (lb - fb);
    } else {
      if (rc) ans += (lr - pg);
      if (bc) ans += (lb - pg);
    }
  }
  cout << ans << endl;
  return 0;
}
