#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e15;
const int mx = 2e5 + 5;
const int x_move[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int y_move[] = {0, 0, 1, -1, 1, -1, 1, -1};
int main() {
  int t, q, ca = 1;
  int n;
  long long int pa, pb, pc;
  long long int ans = 0;
  pa = pb = pc = inf;
  long long int pra = 0, prb = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long int v;
    char str[10];
    scanf("%I64d%s", &v, str);
    if (str[0] == 'R') {
      if (pa != inf) {
        pra = max(pra, v - pa);
        ans += v - pa;
      }
      pa = v;
    } else if (str[0] == 'B') {
      if (pb != inf) {
        prb = max(prb, v - pb);
        ans += v - pb;
      }
      pb = v;
    } else {
      if (pb != inf) {
        prb = max(prb, v - pb);
        ans += v - pb;
      }
      if (pa != inf) {
        pra = max(pra, v - pa);
        ans += v - pa;
      }
      if (pc != inf) ans = min(ans, ans + v - pc - pra - prb);
      pa = pb = pc = v;
      pra = prb = 0;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
