#include <bits/stdc++.h>
using namespace std;
vector<long long> A, B, C;
long long n, ans, b, c;
int main() {
  long long i, j, a, t, k, s;
  char str[5];
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld%s", &a, str);
    if (str[0] == 'P')
      A.push_back(a);
    else if (str[0] == 'R')
      B.push_back(a);
    else
      C.push_back(a);
  }
  if (A.size() == 0) {
    if (B.size()) ans += B.back() - B[0];
    if (C.size()) ans += C.back() - C[0];
    printf("%lld\n", ans);
    return 0;
  }
  if (B.size() && B[0] < A[0]) ans += A[0] - B[0];
  for (b = 0; b < B.size() && B[b] < A[0]; b++)
    ;
  if (C.size() && C[0] < A[0]) ans += A[0] - C[0];
  for (c = 0; c < C.size() && C[c] < A[0]; c++)
    ;
  for (i = 0; i < A.size() - 1; i++) {
    s = 0;
    for (j = b; j < B.size() && B[j] < A[i + 1]; j++)
      ;
    j--;
    if (b <= j && j < B.size()) {
      t = max(B[b] - A[i], A[i + 1] - B[j]);
      for (k = b; k < j; k++) t = max(t, B[k + 1] - B[k]);
      s += A[i + 1] - A[i] - t;
    }
    b = j + 1;
    for (j = c; j < C.size() && C[j] < A[i + 1]; j++)
      ;
    j--;
    if (c <= j && j < C.size()) {
      t = max(C[c] - A[i], A[i + 1] - C[j]);
      for (k = c; k < j; k++) t = max(t, C[k + 1] - C[k]);
      s += A[i + 1] - A[i] - t;
    }
    c = j + 1;
    ans += min(s, A[i + 1] - A[i]) + A[i + 1] - A[i];
  }
  if (b < B.size()) ans += B.back() - A.back();
  if (c < C.size()) ans += C.back() - A.back();
  printf("%lld\n", ans);
  return 0;
}
