#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long int> v[2];
const long long int N = 3e5 + 5;
long long int x[N];
char ch[N];
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int n;
  cin >> n;
  long long int idx = 0;
  long long int ans = 0;
  long long int min1 = 1e12, max1 = 0, min2 = 1e12, max2 = 0;
  for (long long int i = 1; i <= n; i++) {
    cin >> x[i] >> ch[i];
    if (ch[i] == 'G') {
      idx = i;
    }
    if (ch[i] == 'R') {
      min1 = min(min1, x[i]);
      max1 = max(max1, x[i]);
    }
    if (ch[i] == 'B') {
      min2 = min(min2, x[i]);
      max2 = max(max2, x[i]);
    }
  }
  if (!idx) {
    long long int ans = 0;
    if (max2 >= min2) ans += max2 - min2;
    if (max1 >= min1) ans += max1 - min1;
    cout << ans;
    return 0;
  }
  idx = 0;
  for (long long int i = 1; i <= n; i++) {
    if (ch[i] == 'G') {
      if (idx) {
        v[0].clear();
        v[1].clear();
        long long int tot = x[i] - x[idx];
        for (long long int j = idx; j <= i; j++) {
          if (ch[j] == 'R' || ch[j] == 'G') v[0].push_back(x[j]);
          if (ch[j] == 'B' || ch[j] == 'G') v[1].push_back(x[j]);
        }
        long long int sz = v[0].size();
        long long int max1 = 0, max2 = 0;
        for (long long int j = 0; j <= sz - 2; j++) {
          max1 = max(max1, v[0][j + 1] - v[0][j]);
        }
        sz = v[1].size();
        for (long long int j = 0; j <= sz - 2; j++) {
          max2 = max(max2, v[1][j + 1] - v[1][j]);
        }
        tot += 2 * (x[i] - x[idx]) - max1 - max2;
        tot = min(tot, 2 * (x[i] - x[idx]));
        ans += tot;
      } else {
        for (long long int j = 1; j <= i - 1; j++) {
          if (ch[j] == 'B') {
            ans += x[i] - x[j];
            break;
          }
        }
        for (long long int j = 1; j <= i - 1; j++) {
          if (ch[j] == 'R') {
            ans += x[i] - x[j];
            break;
          }
        }
      }
      idx = i;
    }
  }
  for (long long int j = n; j > idx; j--) {
    if (ch[j] == 'R') {
      ans += x[j] - x[idx];
      break;
    }
  }
  for (long long int j = n; j > idx; j--) {
    if (ch[j] == 'B') {
      ans += x[j] - x[idx];
      break;
    }
  }
  cout << ans;
  return 0;
}
