#include <bits/stdc++.h>
using namespace std;
vector<int> greenPos, redBeforeFirstGreenPos, blueBeforeFirstGreenPos;
vector<vector<int>> redAfterGreenPos;
vector<vector<int>> blueAfterGreenPos;
int main() {
  long long res = 0;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int pos;
    char color;
    scanf("%d %c", &pos, &color);
    if (color == 'G') {
      greenPos.push_back(pos);
      redAfterGreenPos.push_back(vector<int>());
      blueAfterGreenPos.push_back(vector<int>());
    } else {
      if (greenPos.size() > 0) {
        int seqNum = int(greenPos.size()) - 1;
        if (color == 'R')
          redAfterGreenPos[seqNum].push_back(pos);
        else
          blueAfterGreenPos[seqNum].push_back(pos);
      } else {
        if (color == 'R')
          redBeforeFirstGreenPos.push_back(pos);
        else
          blueBeforeFirstGreenPos.push_back(pos);
      }
    }
  }
  for (int i = 0; i < int(greenPos.size()) - 1; i++) {
    long long partRes1 = greenPos[i + 1] - greenPos[i];
    long long partRes2 = (greenPos[i + 1] - greenPos[i]) * 2;
    if (redAfterGreenPos[i].size() > 0) {
      partRes1 += greenPos[i + 1] - greenPos[i];
      int mx = redAfterGreenPos[i][0] - greenPos[i];
      for (int j = 1; j < redAfterGreenPos[i].size(); j++) {
        mx = max(mx, redAfterGreenPos[i][j] - redAfterGreenPos[i][j - 1]);
      }
      mx = max(mx, greenPos[i + 1] -
                       redAfterGreenPos[i][redAfterGreenPos[i].size() - 1]);
      partRes1 -= mx;
    }
    if (blueAfterGreenPos[i].size() > 0) {
      partRes1 += greenPos[i + 1] - greenPos[i];
      int mx = blueAfterGreenPos[i][0] - greenPos[i];
      for (int j = 1; j < blueAfterGreenPos[i].size(); j++) {
        mx = max(mx, blueAfterGreenPos[i][j] - blueAfterGreenPos[i][j - 1]);
      }
      mx = max(mx, greenPos[i + 1] -
                       blueAfterGreenPos[i][blueAfterGreenPos[i].size() - 1]);
      partRes1 -= mx;
    }
    res += min(partRes1, partRes2);
  }
  for (int i = 1; i < redBeforeFirstGreenPos.size(); i++) {
    res += redBeforeFirstGreenPos[i] - redBeforeFirstGreenPos[i - 1];
  }
  for (int i = 1; i < blueBeforeFirstGreenPos.size(); i++) {
    res += blueBeforeFirstGreenPos[i] - blueBeforeFirstGreenPos[i - 1];
  }
  if (greenPos.size() > 0) {
    if (redBeforeFirstGreenPos.size() > 0) {
      res += greenPos[0] -
             redBeforeFirstGreenPos[redBeforeFirstGreenPos.size() - 1];
    }
    if (blueBeforeFirstGreenPos.size() > 0) {
      res += greenPos[0] -
             blueBeforeFirstGreenPos[blueBeforeFirstGreenPos.size() - 1];
    }
    int index = greenPos.size() - 1;
    if (redAfterGreenPos[index].size() > 0) {
      res += redAfterGreenPos[index][0] - greenPos[index];
      for (int j = 1; j < redAfterGreenPos[index].size(); j++) {
        res += redAfterGreenPos[index][j] - redAfterGreenPos[index][j - 1];
      }
    }
    if (blueAfterGreenPos[index].size() > 0) {
      res += blueAfterGreenPos[index][0] - greenPos[index];
      for (int j = 1; j < blueAfterGreenPos[index].size(); j++) {
        res += blueAfterGreenPos[index][j] - blueAfterGreenPos[index][j - 1];
      }
    }
  }
  cout << res << endl;
  return 0;
}
