#include <bits/stdc++.h>
using namespace std;
int n, lstr = -1, lstg = -1, lstb = -1, a, mxb, mxr;
char c;
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %c", &a, &c);
    if (c == 'B') {
      if (lstb != -1) {
        ans += a - lstb;
        if (lstg != -1) mxb = max(mxb, a - lstb);
      } else if (lstg != -1) {
        ans += a - lstg;
        mxb = a - lstg;
      }
      lstb = a;
      continue;
    }
    if (c == 'R') {
      if (lstr != -1) {
        ans += a - lstr;
        if (lstg != -1) mxr = max(mxr, a - lstr);
      } else if (lstg != -1) {
        ans += a - lstg;
        mxr = a - lstg;
      }
      lstr = a;
      continue;
    }
    if (lstg != -1) ans += a - lstg;
    if (lstb != -1) ans += a - lstb, mxb = max(mxb, a - lstb);
    if (lstr != -1) ans += a - lstr, mxr = max(mxr, a - lstr);
    if (lstg != -1)
      if (lstb != -1 && lstr != -1)
        ans -= max(a - lstg, mxb + mxr);
      else {
        if (lstb != -1) ans -= mxb;
        if (lstr != -1) ans -= mxr;
      }
    mxb = mxr = 0;
    lstb = lstr = -1;
    lstg = a;
  }
  printf("%lld\n", ans);
}
