#include <bits/stdc++.h>
using namespace std;
long long n, ans, rfr = 1e12, rlast, bfr = 1e12, blast;
vector<long long> st[2];
bool green, red, blue;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  long long last = 1e12;
  for (long long i = 0; i < n; ++i) {
    long long x;
    char c;
    cin >> x >> c;
    if (c == 'G') {
      green = 1;
      if (last == 1e12) {
        for (long long j = 0; j < 2; ++j) {
          if (!st[j].empty()) {
            ans += x - st[j][0];
            st[j].clear();
          }
        }
        last = x;
        continue;
      }
      long long res1, res2, tmp = 0;
      res1 = (x - last) * 2;
      res2 = (x - last);
      for (long long j = 0; j < 2; ++j) {
        if (!st[j].empty()) {
          res2 += x - last;
          tmp = max(st[j][0] - last, x - st[j].back());
          for (long long k = 0; k < signed(st[j].size()) - 1; ++k) {
            tmp = max(tmp, st[j][k + 1] - st[j][k]);
          }
          res2 -= tmp;
          st[j].clear();
        }
      }
      ans += min(res1, res2);
      last = x;
    } else if (c == 'R') {
      st[0].push_back(x);
      rfr = min(x, rfr);
      rlast = max(rlast, x);
      red = 1;
    } else {
      st[1].push_back(x);
      bfr = min(bfr, x);
      blast = max(blast, x);
      blue = 1;
    }
  }
  if (!green) {
    if (red) {
      ans += rlast - rfr;
    }
    if (blue) {
      ans += blast - bfr;
    }
    cout << ans;
    return 0;
  }
  for (long long j = 0; j < 2; ++j) {
    if (!st[j].empty()) {
      ans += st[j].back() - last;
      st[j].clear();
    }
  }
  cout << ans;
}
