#include <bits/stdc++.h>
using namespace std;
long long n, x, la, lb, lp, ma, mb, ans;
bool qa, qb, qp;
char s;
int main(void) {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld %c", &x, &s);
    if (s == 'R' || s == 'P') {
      if (qa) {
        ans += x - la;
        ma = max(ma, x - la);
      }
      la = x;
      qa = 1;
    }
    if (s == 'B' || s == 'P') {
      if (qb) {
        ans += x - lb;
        mb = max(mb, x - lb);
      }
      lb = x;
      qb = 1;
    }
    if (s == 'P') {
      if (qp) ans += min(0ll, x - lp - ma - mb);
      qp = 1;
      lp = x;
      ma = mb = 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
