#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 7;
long long n, ans, cnt;
long long p[N];
long long c[N];
long long w[N];
long long solve(long long l, long long r) {
  if (c[l] || c[r]) return 2 * (p[r] - p[l]);
  long long hr = 0, hb = 0, lr = 1000000007, lb = 1000000007;
  for (long long i = l; i <= r; ++i) {
    if (c[i] != 2) {
      hr = max(hr, p[i] - lr);
      lr = p[i];
    }
    if (c[i] != 1) {
      hb = max(hb, p[i] - lb);
      lb = p[i];
    }
  }
  return min(3 * (p[r] - p[l]) - hr - hb, 2 * (p[r] - p[l]));
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> p[i];
    char t;
    cin >> t;
    if (t == 'G')
      c[i] = 0;
    else if (t == 'R')
      c[i] = 1;
    else if (t == 'B')
      c[i] = 2;
  }
  for (long long i = 1; i <= n; ++i) {
    if (!c[i]) w[++cnt] = i;
  }
  long long fr = -1, fb = -1, lr = -1, lb = -1;
  for (long long i = 1; i <= n; ++i) {
    if (c[i] == 1) {
      if (fr == -1) fr = p[i];
      lr = p[i];
    } else if (c[i] == 2) {
      if (fb == -1) fb = p[i];
      lb = p[i];
    }
  }
  if (cnt == 0) {
    cout << lr - fr + lb - fb;
    exit(0);
  }
  if (fr != -1) {
    ans += max(0ll, p[w[1]] - fr);
    ans += max(0ll, lr - p[w[cnt]]);
  }
  if (fb != -1) {
    ans += max(0ll, p[w[1]] - fb);
    ans += max(0ll, lb - p[w[cnt]]);
  }
  for (long long i = 1; i < cnt; ++i) {
    ans += solve(w[i], w[i + 1]);
  }
  cout << ans;
}
