#include <bits/stdc++.h>
using namespace std;
int n, c[300005], tg, tr, tb, pr = 1, pb = 1, g[300005], r[300005], b[300005];
long long ans;
int main() {
  int x;
  char ch;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %c", &x, &ch);
    if (ch == 'G') g[++tg] = x;
    if (ch == 'R') r[++tr] = x;
    if (ch == 'B') b[++tb] = x;
  }
  for (; r[pr] < g[1] && pr <= tr; pr++) ans += r[pr + 1] - r[pr];
  if (pr > 1) ans += g[1] - r[pr];
  for (; b[pb] < g[1] && pb <= tb; pb++) ans += b[pb + 1] - b[pb];
  if (pb > 1) ans += g[1] - b[pb];
  for (int i = 2; i <= tg; i++) {
    long long res = 0;
    int maxr = 0, maxb = 0;
    for (int pre = g[i - 1]; r[pr] < g[i] && pr <= tr; pre = r[pr++])
      maxr = max(maxr, r[pr] - pre);
    if (r[pr - 1] > g[i - 1])
      maxr = max(maxr, g[i] - r[pr - 1]);
    else
      maxr = g[i] - g[i - 1];
    for (int pre = g[i - 1]; b[pb] < g[i] && pb <= tb; pre = b[pb++])
      maxb = max(maxb, b[pb] - pre);
    if (b[pb - 1] > g[i - 1])
      maxb = max(maxb, g[i] - b[pb - 1]);
    else
      maxb = g[i] - g[i - 1];
    ans += min((g[i] - g[i - 1]) * 3 - maxr - maxb, (g[i] - g[i - 1]) * 2);
  }
  for (int pre = g[tg]; pr <= tr; pre = r[pr++]) ans += r[pr] - pre;
  for (int pre = g[tg]; pb <= tb; pre = b[pb++]) ans += b[pb] - pre;
  if (!tg) ans -= r[1] + b[1];
  printf("%I64d\n", ans);
  return 0;
}
