#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> Blue;
  vector<int> Red;
  int lastGreen = -1;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    char who;
    cin >> x >> who;
    if (who == 'G') {
      Blue.emplace_back(x);
      Red.emplace_back(x);
      if (lastGreen == -1) {
        ans += x - Blue[0];
        ans += x - Red[0];
      } else {
        int len = x - lastGreen;
        int Gb = 0;
        int Gr = 0;
        for (int i = 0; i + 1 < (int)Blue.size(); ++i) {
          Gb = max(Gb, Blue[i + 1] - Blue[i]);
        }
        for (int i = 0; i + 1 < (int)Red.size(); ++i) {
          Gr = max(Gr, Red[i + 1] - Red[i]);
        }
        ans += len - Gb;
        ans += len - Gr;
        if (Gr + Gb <= len)
          ans += Gr + Gb;
        else
          ans += len;
      }
      Red = {x};
      Blue = {x};
      lastGreen = x;
    } else {
      if (who == 'B')
        Blue.emplace_back(x);
      else
        Red.emplace_back(x);
    }
  }
  if (lastGreen == -1) {
    if (Blue.size()) ans += Blue.back() - Blue[0];
    if (Red.size()) ans += Red.back() - Red[0];
  } else {
    ans += Blue.back() - lastGreen;
    ans += Red.back() - lastGreen;
  }
  cout << ans;
}
