#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long ans = 0;
  bool R = 0, G = 0, B = 0;
  long long c = 0, v = 0, d = 0, f = 0, g = 0;
  for (long long x = 1; x <= n; x++) {
    long long m;
    char s;
    cin >> m >> s;
    if (s == 'G' || s == 'R')
      ans += R * (m - d), c = max(c, R * (m - d)), R = 1, d = m;
    if (s == 'G' || s == 'B')
      ans += B * (m - f), v = max(v, B * (m - f)), B = 1, f = m;
    if (s == 'G') ans += G * min(0ll, m - g - c - v), g = m, G = 1, c = v = 0;
  }
  cout << ans;
}
