#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
const long long INF = 1e9;
long long n;
long long p[N];
char c[N];
bool r, g, b;
long long solve() {
  long long ret = 0;
  c[0] = 'G';
  c[n + 1] = 'G';
  long long j = 0;
  for (long long i = 1; i <= n + 1; ++i) {
    if (c[i] != 'G') continue;
    vector<long long> reds;
    vector<long long> blues;
    for (long long k = j + 1; k < i; ++k) {
      if (c[k] == 'R')
        reds.push_back(p[k]);
      else
        blues.push_back(p[k]);
    }
    long long ans = 0;
    if (i != n + 1 && j != 0) ans += p[i] - p[j];
    long long bluegap = 0, redgap = 0;
    if (reds.size() > 0) {
      if (j == 0) {
        ans += p[i] - reds[0];
      } else if (i == n + 1) {
        ans += reds.back() - p[j];
      } else {
        redgap = reds[0] - p[j];
        for (long long k = 1; k < reds.size(); ++k)
          redgap = max(redgap, reds[k] - reds[k - 1]);
        redgap = max(redgap, p[i] - reds.back());
        ans += p[i] - p[j] - redgap;
      }
    }
    if (blues.size() > 0) {
      if (j == 0) {
        ans += p[i] - blues[0];
      } else if (i == n + 1) {
        ans += blues.back() - p[j];
      } else {
        bluegap = blues[0] - p[j];
        for (long long k = 1; k < blues.size(); ++k)
          bluegap = max(bluegap, blues[k] - blues[k - 1]);
        bluegap = max(bluegap, p[i] - blues.back());
        ans += p[i] - p[j] - bluegap;
      }
    }
    if (j != 0 && i != n + 1 && reds.size() > 0 && blues.size() > 0)
      ans = min(ans, 2 * (p[i] - p[j]));
    ret += ans;
    j = i;
  }
  return ret;
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    cin >> p[i] >> c[i];
    if (c[i] == 'R')
      r = 1;
    else if (c[i] == 'G')
      g = 1;
    else
      b = 1;
  }
  if (!g) {
    if (r ^ b) {
      cout << p[n] - p[1] << "\n";
    } else {
      long long mnred = INF;
      long long mxred = -1;
      long long mnblue = INF;
      long long mxblue = -1;
      for (long long i = 1; i <= n; ++i) {
        if (c[i] == 'R') mxred = p[i];
        if (c[i] == 'B') mxblue = p[i];
      }
      for (long long i = n; i >= 1; --i) {
        if (c[i] == 'R') mnred = p[i];
        if (c[i] == 'B') mnblue = p[i];
      }
      cout << (mxred - mnred) + (mxblue - mnblue) << "\n";
    }
  } else {
    cout << solve() << "\n";
  }
  return 0;
}
