#include <bits/stdc++.h>
using namespace std;
const long long M = 1E9 + 7;
const long long NMAX = 300011;
const long long inf = 1000000000;
const long double eps = 1E-10;
long long p[NMAX];
long long c[NMAX];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  cout.precision(40);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> p[i];
    char col;
    cin >> col;
    if (col == 'G')
      c[i] = 0;
    else if (col == 'B')
      c[i] = 1;
    else
      c[i] = 2;
  }
  long long b = 0, r = 0;
  long long mxr = 0;
  long long mxb = 0;
  long long ans = 0;
  long long ansr = 0;
  long long ansb = 0;
  long long g = 0;
  for (long long i = 1; i <= n; i++) {
    if (c[i] == 1) {
      if (b != 0) {
        ansb += p[i] - p[b];
        mxb = max(mxb, p[i] - p[b]);
      }
      b = i;
    } else if (c[i] == 2) {
      if (r != 0) {
        ansr += p[i] - p[r];
        mxr = max(mxr, p[i] - p[r]);
      }
      r = i;
    } else {
      if (b != 0) {
        ansb += p[i] - p[b];
        mxb = max(mxb, p[i] - p[b]);
      }
      if (r != 0) {
        ansr += p[i] - p[r];
        mxr = max(mxr, p[i] - p[r]);
      }
      if (!g)
        ans += ansb + ansr;
      else
        ans += min(3 * (p[i] - p[g]) - mxr - mxb, 2 * (p[i] - p[g]));
      mxr = 0;
      mxb = 0;
      ansr = 0;
      ansb = 0;
      b = i;
      r = i;
      g = i;
    }
  }
  ans += ansb + ansr;
  cout << ans;
  return 0;
};
