#include <bits/stdc++.h>
using namespace std;
long long X[300010], Col[300010], n;
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    char ch[2];
    scanf("%lld%s", &X[i], ch);
    if (ch[0] == 'G') Col[i] = 0;
    if (ch[0] == 'B') Col[i] = 1;
    if (ch[0] == 'R') Col[i] = -1;
  }
  long long l = 1, r = n;
  while (l <= n && Col[l]) l++;
  while (r && Col[r]) r--;
  long long ans = 0;
  if (!r) {
    for (long long i = 1; i <= n; i++)
      if (Col[i] != -1) {
        ans -= X[i];
        break;
      }
    for (long long i = 1; i <= l; i++)
      if (Col[i] != 1) {
        ans -= X[i];
        break;
      }
    for (long long i = n; i >= r; i--)
      if (Col[i] != -1) {
        ans += X[i];
        break;
      }
    for (long long i = n; i >= r; i--)
      if (Col[i] != 1) {
        ans += X[i];
        break;
      }
    printf("%lld\n", ans);
    return 0;
  }
  for (long long i = 1; i <= l; i++)
    if (Col[i] != -1) {
      ans -= X[i];
      break;
    }
  for (long long i = 1; i <= l; i++)
    if (Col[i] != 1) {
      ans -= X[i];
      break;
    }
  for (long long i = n; i >= r; i--)
    if (Col[i] != -1) {
      ans += X[i];
      break;
    }
  for (long long i = n; i >= r; i--)
    if (Col[i] != 1) {
      ans += X[i];
      break;
    }
  ans += X[l] * 2;
  ans -= X[r] * 2;
  for (long long i = l, nxt; i < r; i = nxt) {
    vector<long long> A, B;
    A.clear();
    B.clear();
    A.push_back(i);
    B.push_back(i);
    for (nxt = i + 1; Col[nxt]; nxt++)
      if (Col[nxt] == 1)
        A.push_back(nxt);
      else if (Col[nxt] == -1)
        B.push_back(nxt);
    A.push_back(nxt);
    B.push_back(nxt);
    long long mxA = 0, mxB = 0;
    for (long long j = 1; j < A.size(); j++)
      mxA = max(mxA, X[A[j]] - X[A[j - 1]]);
    for (long long j = 1; j < B.size(); j++)
      mxB = max(mxB, X[B[j]] - X[B[j - 1]]);
    ans += min(2 * (X[nxt] - X[i]), 3 * (X[nxt] - X[i]) - mxA - mxB);
  }
  printf("%lld\n", ans);
}
