#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sign(T a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << "(" << p.first << ", " << p.second << ")";
};
template <class A>
ostream &operator<<(ostream &out, const vector<A> &v) {
  out << "[";
  for (int i = int(0); i < int(int((v).size())); ++i) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int dxK[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dyK[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dxKn[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int dyKn[] = {1, 2, 2, 1, -1, -2, -2, -1};
const int INF = int(1e9) + 100;
const long long INF64 = int(1e18) + 100;
const long double EPS = 1e-9;
const long double PI = acosl(-1.0);
const int N = 300 * 1000 + 9;
int n;
int pos[N];
char col[N];
vector<int> g;
vector<int> r;
vector<int> b;
inline bool read() {
  if (!(cin >> n)) return false;
  for (int i = int(0); i < int(n); ++i) {
    cin >> pos[i] >> col[i];
    if (col[i] == 'G')
      g.push_back(i);
    else if (col[i] == 'R')
      r.push_back(i);
    else
      b.push_back(i);
  }
  return true;
}
int calc(int l, int r) {
  int dist = pos[r - 1] - pos[l];
  int mxR = -1, mxB = -1;
  int lstR = -1, lstB = -1;
  for (int i = int(l); i < int(r); ++i) {
    if (col[i] == 'R' || col[i] == 'G') {
      if (lstR != -1) mxR = max(mxR, pos[i] - pos[lstR]);
      lstR = i;
    }
    if (col[i] == 'B' || col[i] == 'G') {
      if (lstB != -1) mxB = max(mxB, pos[i] - pos[lstB]);
      lstB = i;
    }
  }
  int res = dist;
  if (mxR != -1) res += dist - mxR;
  if (mxB != -1) res += dist - mxB;
  if (mxR != -1 && mxB != -1) res = min(res, 2 * dist);
  return res;
}
int calcPref(vector<int> r, vector<int> g) {
  if (int((r).size()) > 0 && r[0] < g[0]) return pos[g[0]] - pos[r[0]];
  return 0;
}
int calcSuff(vector<int> r, vector<int> g) {
  if (int((r).size()) > 0 && r.back() > g.back())
    return pos[r.back()] - pos[g.back()];
  return 0;
}
inline void solve() {
  int res = 0;
  for (int i = 1; i < int(int((g).size())); ++i)
    res += calc(g[i - 1], g[i] + 1);
  if (int((g).size()) == 0) {
    if (int((r).size()) > 0) res += pos[r.back()] - pos[r[0]];
    if (int((b).size()) > 0) res += pos[b.back()] - pos[b[0]];
  } else {
    res += calcPref(r, g);
    ;
    res += calcPref(b, g);
    res += calcSuff(r, g);
    ;
    res += calcSuff(b, g);
  }
  cout << res << endl;
}
int main() {
  cout << fixed << setprecision(15);
  cerr << fixed << setprecision(15);
  if (read()) {
    solve();
  }
  return 0;
}
