#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
int main() {
  cin.sync_with_stdio(0);
  ll n;
  cin >> n;
  vector<pair<ll, char>> dots(n);
  vl reds, greens, blues;
  for (auto& dot : dots) {
    cin >> dot.first >> dot.second;
    if (dot.second == 'G') {
      greens.push_back(dot.first);
    } else if (dot.second == 'R') {
      reds.push_back(dot.first);
    } else {
      blues.push_back(dot.first);
    }
  }
  if (!ll((greens).size())) {
    ll res = 0;
    if (ll((reds).size()) > 1) {
      res += reds.back() - reds[0];
    }
    if (ll((blues).size()) > 1) {
      res += blues.back() - blues[0];
    }
    cout << res << endl;
    return 0;
  }
  ll res = 0;
  if (ll((reds).size())) {
    if (reds[0] < greens[0]) {
      res += greens[0] - reds[0];
    }
    if (reds.back() > greens.back()) {
      res += reds.back() - greens.back();
    }
  }
  if (ll((blues).size())) {
    if (blues[0] < greens[0]) {
      res += greens[0] - blues[0];
    }
    if (blues.back() > greens.back()) {
      res += blues.back() - greens.back();
    }
  }
  ll le = 0;
  while (dots[le].second != 'G') {
    le++;
  }
  ll ri = le;
  while (true) {
    vl red;
    red.push_back(dots[le].first);
    vl blue;
    blue.push_back(dots[le].first);
    ri++;
    while (ri < n && dots[ri].second != 'G') {
      if (dots[ri].second == 'R') {
        red.push_back(dots[ri].first);
      } else if (dots[ri].second == 'B') {
        blue.push_back(dots[ri].first);
      }
      ri++;
    }
    if (ri == n) {
      break;
    }
    red.push_back(dots[ri].first);
    blue.push_back(dots[ri].first);
    ll pres = 2ll * (dots[ri].first - dots[le].first);
    ll rgap = 0, bgap = 0;
    for (ll i = (1); i < (ll((red).size())); i++) {
      rgap = max(rgap, red[i] - red[i - 1]);
    }
    for (ll i = (1); i < (ll((blue).size())); i++) {
      bgap = max(bgap, blue[i] - blue[i - 1]);
    }
    pres = min(pres, 3ll * (dots[ri].first - dots[le].first) - rgap - bgap);
    res += pres;
    le = ri;
  }
  cout << res << endl;
}
