#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], bor, bog, bob, maxr, maxb;
long long ans;
char s[100];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%s", &a[i], s);
    if (s[0] == 'G') {
      if (bor) {
        ans += a[i] - a[bor];
        maxr = max(maxr, a[i] - a[bor]);
      }
      bor = i;
      if (bob) {
        ans += a[i] - a[bob];
        maxb = max(maxb, a[i] - a[bob]);
      }
      bob = i;
      if (bog) ans += min(0, a[i] - a[bog] - maxb - maxr);
      maxb = maxr = 0;
      bog = i;
    }
    if (s[0] == 'R') {
      if (bor) {
        ans += a[i] - a[bor];
        maxr = max(maxr, a[i] - a[bor]);
      }
      bor = i;
    }
    if (s[0] == 'B') {
      if (bob) {
        ans += a[i] - a[bob];
        maxb = max(maxb, a[i] - a[bob]);
      }
      bob = i;
    }
  }
  printf("%lld", ans);
}
