#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  int lasg = 0, lasr = 0, lasb = 0;
  int mxr = 0, mxb = 0;
  int r1 = 0, b1 = 0;
  for (int i = (1); i <= (n); i++) {
    int p;
    char c;
    cin >> p >> c;
    if (c == 'G') {
      if (!lasg) {
        if (r1) ans += p - r1;
        if (b1) ans += p - b1;
      } else {
        mxr = max(mxr, min(p - lasr, p - lasg));
        mxb = max(mxb, min(p - lasb, p - lasg));
        ans += min((long long)(p - lasg) * 2,
                   (long long)(p - lasg) * 3 - mxr - mxb);
      }
      lasg = p;
      lasr = lasb = mxr = mxb = 0;
    } else if (c == 'R') {
      if (lasr || lasg) mxr = max(mxr, min(p - lasr, p - lasg));
      lasr = p;
      if (!r1) r1 = p;
    } else {
      if (lasb || lasg) mxb = max(mxb, min(p - lasb, p - lasg));
      lasb = p;
      if (!b1) b1 = p;
    }
  }
  if (lasr) {
    if (lasg)
      ans += lasr - lasg;
    else
      ans += lasr - r1;
  }
  if (lasb) {
    if (lasg)
      ans += lasb - lasg;
    else
      ans += lasb - b1;
  }
  printf("%lld\n", ans);
  return 0;
}
