#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int num[n];
  vector<long long int> G;
  vector<long long int> R;
  vector<long long int> B;
  long long int prev = -1;
  long long int ans = 0;
  long long int flag = 1;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> num[i];
    cin >> c;
    if (c == 'G') {
      flag = 0;
      if (prev == -1) {
        prev = num[i];
        R.push_back(num[i]);
        B.push_back(num[i]);
        ans += num[i] - R[0];
        ans += num[i] - B[0];
        R.clear();
        B.clear();
        R.push_back(num[i]);
        B.push_back(num[i]);
        long long int sdas;
      } else {
        R.push_back(num[i]);
        B.push_back(num[i]);
        long long int xr = -1, xb = -1;
        for (int k = 1; k < R.size(); ++k) {
          xr = max(xr, R[k] - R[k - 1]);
        }
        for (int k = 1; k < B.size(); ++k) {
          xb = max(xb, B[k] - B[k - 1]);
        }
        if (R.size() == 2 && B.size() == 2) {
          ans += (num[i] - prev);
        } else if (R.size() == 2) {
          ans += 2 * (num[i] - prev) - xb;
        } else if (B.size() == 2) {
          ans += 2 * (num[i] - prev) - xr;
        } else
          ans += min(3 * (num[i] - prev) - xr - xb, 2 * (num[i] - prev));
        prev = num[i];
        R.clear();
        B.clear();
        R.push_back(num[i]);
        B.push_back(num[i]);
      }
    } else {
      if (c == 'R') {
        R.push_back(num[i]);
      }
      if (c == 'B') {
        B.push_back(num[i]);
      }
    }
  }
  if (R.size() > 0) {
    ans += R[R.size() - 1] - R[0];
  }
  if (B.size() > 0) {
    ans += B[B.size() - 1] - B[0];
  }
  cout << ans << endl;
  return 0;
}
