#include <bits/stdc++.h>
using namespace std;
vector<int> vec[3];
int solve() {
  int ans = 0, cur = 0, r1 = 0, r2, b1 = 0, b2, temp1, temp2;
  while (r1 < vec[1].size() && vec[1][r1] < vec[0][0]) r1++;
  while (b1 < vec[2].size() && vec[2][b1] < vec[0][0]) b1++;
  cur++;
  if (r1) ans += vec[0][0] - vec[1][0];
  if (b1) ans += vec[0][0] - vec[2][0];
  while (cur < vec[0].size()) {
    r2 = r1;
    b2 = b1;
    while (r2 < vec[1].size() && vec[1][r2] < vec[0][cur]) r2++;
    while (b2 < vec[2].size() && vec[2][b2] < vec[0][cur]) b2++;
    temp1 = temp2 = 0;
    if (r2 - r1) {
      temp1 = min(vec[1][r2 - 1] - vec[0][cur - 1], vec[0][cur] - vec[1][r1]);
      for (int k = 1; k < r2 - r1; k++)
        temp1 = min(temp1, vec[1][r1 + k - 1] - vec[0][cur - 1] + vec[0][cur] -
                               vec[1][r1 + k]);
      r1 = r2;
    }
    if (b2 - b1) {
      temp2 = min(vec[2][b2 - 1] - vec[0][cur - 1], vec[0][cur] - vec[2][b1]);
      for (int k = 1; k < b2 - b1; k++)
        temp2 = min(temp2, vec[2][b1 + k - 1] - vec[0][cur - 1] + vec[0][cur] -
                               vec[2][b1 + k]);
      b1 = b2;
    }
    ans += min(2 * (vec[0][cur] - vec[0][cur - 1]),
               (vec[0][cur] - vec[0][cur - 1]) + temp1 + temp2);
    cur++;
  }
  if (r1 != vec[1].size()) ans += vec[1].back() - vec[0].back();
  if (b1 != vec[2].size()) ans += vec[2].back() - vec[0].back();
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    char c;
    scanf("%d %c", &x, &c);
    if (c == 'G')
      vec[0].push_back(x);
    else if (c == 'R')
      vec[1].push_back(x);
    else
      vec[2].push_back(x);
  }
  int ans = 0;
  if (vec[0].size() == 0) {
    if (vec[1].size()) ans += vec[1].back() - vec[1][0];
    if (vec[2].size()) ans += vec[2].back() - vec[2][0];
    printf("%d\n", ans);
    return 0;
  }
  printf("%d\n", solve());
  return 0;
}
