#include <bits/stdc++.h>
using std::max;
using std::min;
const int N = 300005;
int a[N], b[N], c[N], ans, n, lred, lblue, rred, rblue, cnt;
char s[10];
void init() {
  for (int i = 1; i <= n; i++) {
    if (c[i] == 1 && !lred) lred = a[i];
    if (c[i] == 2 && !lblue) lblue = a[i];
  }
  for (int i = n; i >= 1; i--) {
    if (c[i] == 1 && !rred) rred = a[i];
    if (c[i] == 2 && !rblue) rblue = a[i];
  }
  if (lred && lred < a[b[1]]) ans = ans + a[b[1]] - lred;
  if (lblue && lblue < a[b[1]]) ans = ans + a[b[1]] - lblue;
  if (rred > a[b[cnt]]) ans = ans + rred - a[b[cnt]];
  if (rblue > a[b[cnt]]) ans = ans + rblue - a[b[cnt]];
}
int solve(int l, int r) {
  int t1 = a[l], t2 = a[l], mx1 = 0, mx2 = 0;
  for (int i = l + 1; i < r; i++) {
    if (c[i] == 1) mx1 = max(mx1, a[i] - t1), t1 = a[i];
    if (c[i] == 2) mx2 = max(mx2, a[i] - t2), t2 = a[i];
  }
  mx1 = max(a[r] - t1, mx1);
  mx2 = max(a[r] - t2, mx2);
  return mx1 + mx2;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    scanf("%s", s + 1);
    if (s[1] == 'G')
      c[i] = 0, b[++cnt] = i;
    else if (s[1] == 'B')
      c[i] = 2;
    else
      c[i] = 1;
  }
  init();
  if (cnt == 0) {
    printf("%d\n", rred - lred + rblue - lblue);
    return 0;
  }
  for (int i = 1; i < cnt; i++) {
    int t = a[b[i + 1]] - a[b[i]];
    ans = ans + min(t * 2, t * 3 - solve(b[i], b[i + 1]));
  }
  printf("%d\n", ans);
}
