#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
const double EPS = 1e-11;
int n;
long long p[353531];
int type[353531];
char buf[353];
int main() {
  scanf("%d", &n);
  p[0] = -1000000000000ll;
  bool existg = false;
  for (int i = 0; i < (int)(n); ++i) {
    int tmp;
    scanf("%d", &tmp);
    scanf("%s", buf);
    p[i + 1] = (long long)tmp;
    type[i + 1] = buf[0] == 'G' ? 0 : (buf[0] == 'R' ? 1 : 2);
    if (type[i + 1] == 0) existg = true;
  }
  if (!existg) {
    long long ans = 0;
    int fr = n + 10, er = -1, fb = n + 10, eb = -1;
    for (int i = (int)(1); i < (int)(n + 1); ++i) {
      if (type[i] == 1)
        fr = min((fr), (i)), er = max((er), (i));
      else
        fb = min((fb), (i)), eb = max((eb), (i));
    }
    if (fr <= er) ans += p[er] - p[fr];
    if (fb <= eb) ans += p[eb] - p[fb];
    cout << ans << endl;
    return 0;
  }
  p[n + 1] = 100000000000000ll;
  long long ans = 0;
  bool first = true;
  long long last = 0;
  int befg = 0, befr = 0, befb = 0;
  long long maxr = 0, maxb = 0;
  for (int i = (int)(1); i < (int)(n + 2); ++i) {
    if (type[i] != 0) {
      if (type[i] == 1) {
        maxr = max((maxr), (p[i] - p[befr]));
        befr = i;
      } else {
        maxb = max((maxb), (p[i] - p[befb]));
        befb = i;
      }
    } else {
      maxr = max((maxr), (p[i] - p[befr]));
      maxb = max((maxb), (p[i] - p[befb]));
      long long len = p[i] - p[befg];
      ans += min(len + (len - maxr) + (len - maxb), len + len);
      if (first) {
        ans -= len;
        first = false;
      }
      last = len;
      befg = befr = befb = i;
      maxr = maxb = 0;
    }
  }
  ans -= last;
  cout << ans << endl;
  return 0;
}
