#include <bits/stdc++.h>
using namespace std;
vector<long long> A, B;
const long long INF = 1e15;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0, maxa = 0, maxb = 0, prea = 0, preb = 0, prec = 0;
  bool numa = 0, numb = 0, numc = 0;
  long long num;
  char c;
  for (int i = 1; i <= n; i++) {
    cin >> num >> c;
    if (c == 'B' || c == 'P') {
      if (numa) {
        ans += num - prea;
        maxa = max(maxa, num - prea);
      }
      numa = 1;
      prea = num;
    }
    if (c == 'R' || c == 'P') {
      if (numb) {
        ans += num - preb;
        maxb = max(maxb, num - preb);
      }
      numb = 1;
      preb = num;
    }
    if (c == 'P') {
      if (numc) {
        ans += min(0ll, num - prec - maxa - maxb);
      }
      prec = num;
      numc = 1;
      maxa = maxb = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
