#include <bits/stdc++.h>
using namespace std;
pair<int, char> points[300029];
int main() {
  int n;
  int last_g = -1, last_r = -1, last_b = -1;
  int max_r = 0, max_b = 0;
  int end_g = -1;
  long long totalcost = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %c", &points[i].first, &points[i].second);
    if (points[i].second == 'G') end_g = i;
  }
  int i = 0;
  while (last_g == -1 && i < n) {
    if (points[i].second == 'G') {
      if (last_b >= 0) totalcost += points[i].first - last_b;
      if (last_r >= 0) totalcost += points[i].first - last_r;
      last_b = last_r = last_g = points[i].first;
      i++;
      break;
    }
    if (points[i].second == 'R') {
      if (last_r >= 0) totalcost += points[i].first - last_r;
      last_r = points[i].first;
    }
    if (points[i].second == 'B') {
      if (last_b >= 0) totalcost += points[i].first - last_b;
      last_b = points[i].first;
    }
    i++;
  }
  for (; i <= end_g; i++) {
    switch (points[i].second) {
      case 'G':
        if (points[i].first - last_r > max_r) max_r = points[i].first - last_r;
        if (points[i].first - last_b > max_b) max_b = points[i].first - last_b;
        totalcost += min(3 * (points[i].first - last_g) - max_b - max_r,
                         2 * (points[i].first - last_g));
        last_b = last_r = last_g = points[i].first;
        max_b = max_r = 0;
        break;
      case 'R':
        if (points[i].first - last_r > max_r) max_r = points[i].first - last_r;
        last_r = points[i].first;
        break;
      case 'B':
        if (points[i].first - last_b > max_b) max_b = points[i].first - last_b;
        last_b = points[i].first;
        break;
    }
  }
  for (; i < n; i++) {
    if (points[i].second == 'R') {
      totalcost += points[i].first - last_r;
      last_r = points[i].first;
    }
    if (points[i].second == 'B') {
      totalcost += points[i].first - last_b;
      last_b = points[i].first;
    }
  }
  printf("%lld\n", totalcost);
  return 0;
}
