#include <bits/stdc++.h>
using namespace std;
int N;
int X[300000];
char C[300000];
vector<int> R, G, B;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < (N); i++) {
    cin >> X[i] >> C[i];
    if (C[i] == 'R')
      R.push_back(i);
    else if (C[i] == 'G')
      G.push_back(i);
    else
      B.push_back(i);
  }
  long long s = 0;
  if (G.empty()) {
    if (!R.empty()) s += X[R.back()] - X[R.front()];
    if (!B.empty()) s += X[B.back()] - X[B.front()];
  } else {
    if (!R.empty() && R.front() < G.front()) s += X[G.front()] - X[R.front()];
    if (!B.empty() && B.front() < G.front()) s += X[G.front()] - X[B.front()];
    if (!R.empty() && R.back() > G.back()) s += X[R.back()] - X[G.back()];
    if (!B.empty() && B.back() > G.back()) s += X[B.back()] - X[G.back()];
    int head_r = 0, head_b = 0;
    for (int i = 0; i < (((int)G.size()) - 1); i++) {
      int l = G[i], r = G[i + 1];
      while (head_r < R.size() && R[head_r] <= l) head_r++;
      vector<int> rs;
      rs.push_back(X[l]);
      while (head_r < R.size() && R[head_r] <= r) rs.push_back(X[R[head_r++]]);
      rs.push_back(X[r]);
      while (head_b < B.size() && B[head_b] <= l) head_b++;
      vector<int> bs;
      bs.push_back(X[l]);
      while (head_b < B.size() && B[head_b] <= r) bs.push_back(X[B[head_b++]]);
      bs.push_back(X[r]);
      long long e = X[r] - X[l];
      {
        e += X[r] - X[l];
        int m = 0;
        for (int i = 0; i < (rs.size() - 1); i++) m = max(m, rs[i + 1] - rs[i]);
        e -= m;
      }
      {
        e += X[r] - X[l];
        int m = 0;
        for (int i = 0; i < (bs.size() - 1); i++) m = max(m, bs[i + 1] - bs[i]);
        e -= m;
      }
      e = min(e, 2LL * (X[r] - X[l]));
      s += e;
    }
  }
  cout << s << "\n";
  return 0;
}
