#include <bits/stdc++.h>
using namespace std;
long long n, ans = 0;
int main() {
  scanf("%lld", &n);
  long long d, c, f, v, g;
  bool r = false, b = false, p = false;
  for (int i = 1; i <= n; i++) {
    long long m;
    char s;
    scanf("%lld %c", &m, &s);
    if (s == 'P' || s == 'R') {
      if (r) {
        ans += m - d;
        c = max(c, m - d);
      }
      r = true;
      d = m;
    }
    if (s == 'P' || s == 'B') {
      if (b) {
        ans += m - f;
        v = max(v, m - f);
      }
      b = true;
      f = m;
    }
    if (s == 'P') {
      if (p) ans += min(0ll, m - g - v - c);
      p = true;
      c = v = 0;
      g = m;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
