#include <bits/stdc++.h>
using namespace std;
int n, x, pr, pb, pg, mr, mb, ans = 0;
char s[10];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%s", &x, s);
    if (s[0] == 'R' || s[0] == 'G') {
      if (pr) {
        ans += x - pr;
        mr = max(mr, x - pr);
      }
      pr = x;
    }
    if (s[0] == 'B' || s[0] == 'G') {
      if (pb) {
        ans += x - pb;
        mb = max(mb, x - pb);
      }
      pb = x;
    }
    if (s[0] == 'G') {
      if (pg) ans += min(0, x - pg - mr - mb);
      pg = x;
      mr = 0;
      mb = 0;
    }
  }
  printf("%d", ans);
  return 0;
}
