#include <bits/stdc++.h>
using namespace std;
const long long INF = -1000000005;
int dis[200005];
int w[200005];
int q[200005];
int main() {
  long long ans = 0;
  int n;
  cin >> n;
  int x;
  char s[10];
  bool bb, rr, pp;
  bb = rr = pp = false;
  long long preb, prer, prep;
  long long mr, mb;
  mr = mb = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %s", &x, s);
    if (s[0] == 'B' || s[0] == 'P') {
      if (bb) {
        ans += x - preb;
        mb = max(mb, x - preb);
      }
      preb = x;
      bb = true;
    }
    if (s[0] == 'R' || s[0] == 'P') {
      if (rr) {
        ans += x - prer;
        mr = max(mr, x - prer);
      }
      prer = x;
      rr = true;
    }
    if (s[0] == 'P') {
      if (pp) {
        ans += min(0LL, x - prep - mr - mb);
      }
      mr = mb = 0;
      prep = x;
      pp = true;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
