#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 10;
long long ans;
int n, last_pos_R, last_pos_B, last_pos_P, max_R, max_B;
int main() {
  int pos;
  char type;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    last_pos_R = last_pos_B = last_pos_P = -0x3f3f3f3f;
    max_R = max_B = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d %c%*c", &pos, &type);
      if (type == 'R' || type == 'P') {
        if (last_pos_R != -0x3f3f3f3f) {
          ans += (pos - last_pos_R);
          max_R = max(max_R, pos - last_pos_R);
        }
        { last_pos_R = pos; }
      }
      if (type == 'B' || type == 'P') {
        if (last_pos_B != -0x3f3f3f3f) {
          ans += (pos - last_pos_B);
          max_B = max(max_B, pos - last_pos_B);
        }
        { last_pos_B = pos; }
      }
      if (type == 'P') {
        if (last_pos_P != -0x3f3f3f3f) {
          ans += min(0, pos - last_pos_P - max_R - max_B);
        }
        last_pos_P = pos;
        max_R = max_B = 0;
      }
    }
    cout << ans << endl;
  }
}
