#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 9;
const int maxn = 2e5 + 7;
const int maxm = 1e7 + 7;
int P[maxn], Q[maxn], m, n;
bool check(int x) { return x != -1e9 - 1; }
int main() {
  scanf("%d", &n);
  long long preP = -1e9 - 1, preR = -1e9 - 1, preB = -1e9 - 1;
  long long maxB = 0, maxR = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    long long k;
    char ch;
    scanf("%I64d %c", &k, &ch);
    if (ch == 'B') {
      if (check(preB) || check(preP)) {
        sum += k - max(preP, preB);
      }
      if (preB > preP)
        maxB = max(maxB, k - preB);
      else if (check(preP) && !check(preB))
        maxB = max(maxB, k - preP);
      preB = k;
    } else if (ch == 'R') {
      if (check(preR) || check(preP)) {
        sum += k - max(preR, preP);
      }
      if (preR > preP)
        maxR = max(maxR, k - preR);
      else if (check(preP) && !check(preR))
        maxR = max(maxR, k - preP);
      preR = k;
    } else {
      if (check(preR)) maxR = max(maxR, k - preR);
      if (check(preB)) maxB = max(maxB, k - preB);
      if (check(preP)) {
        sum += k - preP;
        if (check(preR) && check(preB)) {
          sum += k * 2 - preB - preR;
          sum -= max(k - preP, maxB + maxR);
        } else if (check(preR)) {
          sum += k - preR;
          sum -= maxR;
        } else if (check(preB)) {
          sum += k - preB;
          sum -= maxB;
        }
      } else {
        if (check(preR)) sum += k - preR;
        if (check(preB)) sum += k - preB;
      }
      maxB = 0;
      maxR = 0;
      preB = -1e9 - 1;
      preR = -1e9 - 1;
      preP = k;
    }
  }
  cout << sum << endl;
  return 0;
}
