#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long inl() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
inline double ind() {
  double x;
  scanf("%lf", &x);
  return x;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) {
    int y = power(x, n / 2);
    return y * y;
  } else
    return x * power(x, n - 1);
}
char s[2];
int n, k;
long long ans;
int lastp, lastb, lastr;
int pf, rf, bf;
int c, v, g;
int main() {
  n = in();
  int lastb, lastp, lastr;
  for (int i = 0; i < n; i++) {
    scanf("%d %s", &k, s);
    if (s[0] == 'P' || s[0] == 'R') {
      if (rf) {
        ans += k - lastr;
        c = max(c, k - lastr);
      }
      rf = 1;
      lastr = k;
    }
    if (s[0] == 'P' || s[0] == 'B') {
      if (bf) {
        ans += k - lastb;
        v = max(v, k - lastb);
      }
      bf = 1;
      lastb = k;
    }
    if (s[0] == 'P') {
      if (pf) {
        ans += min(0, k - g - c - v);
      }
      pf = 1;
      g = k;
      c = v = 0;
    }
  }
  printf("%I64d\n", ans);
}
