#include <bits/stdc++.h>
using namespace std;
vector<long long> r, b, p;
long long choose(const vector<long long>& v, long long l, long long r) {
  long long x = lower_bound(v.begin(), v.end(), l) - v.begin();
  long long y = lower_bound(v.begin(), v.end(), r) - v.begin();
  long long tmp = 0;
  for (long long i = x; i < y; i++) {
    tmp = max(tmp, v[i + 1] - v[i]);
  }
  return tmp;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    if (c == 'R') {
      r.push_back(x);
    } else if (c == 'P') {
      r.push_back(x);
      b.push_back(x);
      p.push_back(x);
    } else {
      b.push_back(x);
    }
  }
  long long ans = 0;
  long long nr = r.size(), nb = b.size(), np = p.size();
  if (nr > 1) ans += r[nr - 1] - r[0];
  if (nb > 1) ans += b[nb - 1] - b[0];
  if (!np || np == 1) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i < np - 1; i++) {
    long long l = p[i], rr = p[i + 1];
    ans -= max(0LL, choose(b, l, rr) + choose(r, l, rr) - (rr - l));
  }
  cout << ans << endl;
  return 0;
}
