#include <bits/stdc++.h>
using namespace std;
int n, x, maxR, maxB, lastR, lastB, lastG, firstB, firstR;
long long ans;
char s[5];
bool flag;
int main() {
  scanf("%d", &n);
  for (; n; n--) {
    scanf("%d%s", &x, s);
    if (s[0] == 'G') {
      if (flag) {
        int L = x - lastG;
        maxR = max(x - lastR, maxR);
        maxB = max(x - lastB, maxB);
        ans += min(3 * L - maxR - maxB, 2 * L);
        maxR = maxB = 0;
        lastR = lastB = lastG = x;
      } else {
        if (firstR) ans += x - firstR;
        if (firstB) ans += x - firstB;
        lastR = lastB = lastG = x;
        flag = 1;
      }
    } else if (!flag) {
      if (s[0] == 'R') {
        if (!firstR) firstR = x;
        lastR = x;
      }
      if (s[0] == 'B') {
        if (!firstB) firstB = x;
        lastB = x;
      }
    } else if (s[0] == 'R') {
      maxR = max(maxR, x - lastR);
      lastR = x;
    } else if (s[0] == 'B') {
      maxB = max(maxB, x - lastB);
      lastB = x;
    }
  }
  if (!flag) {
    ans += lastR - firstR;
    ans += lastB - firstB;
  } else {
    ans += lastR - lastG;
    ans += lastB - lastG;
  }
  cout << ans << endl;
}
