#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
const long long N = 3e5 + 10;
long long n, ans = 0, np = 0;
vector<pair<long long, char> > r, b;
void full() {
  long long rs = r.size(), bs = b.size();
  for (int i = 0; i < (rs - 1); i++) ans += r[i + 1].first - r[i].first;
  for (int i = 0; i < (bs - 1); i++) ans += b[i + 1].first - b[i].first;
  cout << ans << endl;
  exit(0);
}
void first(long long rl, long long bl) {
  for (int i = (0); i <= (rl - 1); i++) ans += r[i + 1].first - r[i].first;
  for (int i = (0); i <= (bl - 1); i++) ans += b[i + 1].first - b[i].first;
}
void last(long long rr, long long br) {
  long long rs = r.size(), bs = b.size();
  for (int i = (rs - 1); i >= (rr + 1); i--) ans += r[i].first - r[i - 1].first;
  for (int i = (bs - 1); i >= (br + 1); i--) ans += b[i].first - b[i - 1].first;
}
void next(long long& rl, long long& rr, long long& bl, long long& br) {
  rl = rr, bl = br;
  ++rr, ++br;
  while (r[rr].second != 'G') ++rr;
  while (b[br].second != 'G') ++br;
}
void solveMid(long long rl, long long rr, long long bl, long long br) {
  long long ans1 = 0, ans2 = 0, bm = 0, rm = 0;
  ans1 += r[rr].first - r[rl].first;
  for (int i = (rl); i <= (rr - 1); i++) {
    rm = max(rm, r[i + 1].first - r[i].first);
    ans2 += r[i + 1].first - r[i].first;
  }
  for (int i = (bl); i <= (br - 1); i++) {
    bm = max(bm, b[i + 1].first - b[i].first);
    ans2 += b[i + 1].first - b[i].first;
  }
  ans1 += ans2 - bm - rm;
  if (rl == rr - 1 || bl == br - 1)
    ans += ans1;
  else
    ans += min(ans1, ans2);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < (n); i++) {
    long long x;
    char p;
    cin >> x >> p;
    np += p == 'G';
    if (p != 'B') r.push_back({x, p});
    if (p != 'R') b.push_back({x, p});
  }
  if (np < 2) full();
  long long rl = 0, bl = 0, rr, br;
  while (r[rl].second != 'G') ++rl;
  while (b[bl].second != 'G') ++bl;
  rr = rl, br = bl;
  first(rl, bl);
  for (int repeat = 0; repeat < (np - 1); repeat++) {
    next(rl, rr, bl, br);
    solveMid(rl, rr, bl, br);
  }
  last(rr, br);
  cout << ans << endl;
  return 0;
}
