#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int MAXN = 300228;
vector<ll> rb;
vector<ll> gb;
vector<ll> b;
ll g(const vector<ll>& v, ll l, ll r) {
  int il = lower_bound(v.begin(), v.end(), l) - v.begin();
  int ir = lower_bound(v.begin(), v.end(), r) - v.begin();
  ll an = 0;
  for (int i = il; i < ir; ++i) {
    an = max(an, v[i + 1] - v[i]);
  }
  return an;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    char c;
    cin >> c;
    if (c == 'R') {
      rb.push_back(x);
    } else if (c == 'B') {
      gb.push_back(x);
    } else {
      rb.push_back(x);
      gb.push_back(x);
      b.push_back(x);
    }
  }
  ll ans = 0;
  if (rb.size() > 1) {
    ans += rb.back() - rb.front();
  }
  if (gb.size() > 1) {
    ans += gb.back() - gb.front();
  }
  for (int i = 1; i < b.size(); ++i) {
    ll l = b[i - 1], r = b[i];
    ll sub = g(rb, l, r) + g(gb, l, r);
    ans -= max(0ll, sub - (r - l));
  }
  cout << ans << "\n";
}
