#include <bits/stdc++.h>
using namespace std;
long n;
pair<long, char> a[300005];
long r, g, b;
int main() {
  scanf("%ld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%ld %c", &a[i].first, &a[i].second);
  }
  long long kq = 0, r2 = 0, b2 = 0;
  long ma_r = 0, ma_b = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].second == 'R') {
      if (r > 0) {
        r2 += a[i].first - r;
        ma_r = max(ma_r, a[i].first - r);
      }
      r = a[i].first;
    }
    if (a[i].second == 'G') {
      if (r > 0) {
        r2 += a[i].first - r;
        ma_r = max(ma_r, a[i].first - r);
      }
      r = a[i].first;
      if (b > 0) {
        b2 += a[i].first - b;
        ma_b = max(ma_b, a[i].first - b);
      }
      b = a[i].first;
      if (g > 0) {
        r2 -= ma_r;
        b2 -= ma_b;
        kq += a[i].first - g;
        if (r2 != 0 || b2 != 0) {
          if ((a[i].first - g) > (r2 + b2)) {
            kq += r2 + b2;
          } else {
            kq += a[i].first - g;
          }
        }
      } else {
        kq += r2 + b2;
      }
      r2 = 0;
      b2 = 0;
      ma_r = 0;
      ma_b = 0;
      g = a[i].first;
    }
    if (a[i].second == 'B') {
      if (b > 0) {
        b2 += a[i].first - b;
        ma_b = max(ma_b, a[i].first - b);
      }
      b = a[i].first;
    }
  }
  kq += r2 + b2;
  cout << kq;
}
