#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, char>> a;
  vector<int> gi;
  for (int i = 0; i < n; i++) {
    int first;
    char color;
    cin >> first >> color;
    a.push_back({first, color});
    if (color == 'G') {
      gi.push_back(i);
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int)gi.size() - 1; i++) {
    int leftRed = a[gi[i]].first;
    int leftBlue = a[gi[i]].first;
    int d = a[gi[i + 1]].first - a[gi[i]].first;
    long long redAns = 0, blueAns = 0;
    for (int index = gi[i] + 1; index <= gi[i + 1]; index++) {
      if (a[index].second == 'R') {
        redAns = max(redAns, (long long)a[index].first - leftRed);
        leftRed = a[index].first;
      } else if (a[index].second == 'B') {
        blueAns = max(blueAns, (long long)a[index].first - leftBlue);
        leftBlue = a[index].first;
      } else {
        assert(a[index].second == 'G');
        assert(a[index].first == a[gi[i + 1]].first);
        blueAns = max(blueAns, (long long)a[index].first - leftBlue);
        redAns = max(redAns, (long long)a[index].first - leftRed);
      }
    }
    ans += min((long long)3 * d - redAns - blueAns, (long long)2 * d);
  }
  if ((int)gi.size() <= 1) {
    int lb = -1;
    int lr = -1;
    for (int i = 0; i < (int)a.size(); i++) {
      if (a[i].second == 'B') {
        if (lb == -1) {
          lb = a[i].first;
        } else {
          ans += a[i].first - lb;
          lb = a[i].first;
        }
      } else if (a[i].second == 'R') {
        if (lr == -1) {
          lr = a[i].first;
        } else {
          ans += a[i].first - lr;
          lr = a[i].first;
        }
      } else {
        assert(a[i].second == 'G');
        ans += a[i].first - lr;
        ans += a[i].first - lb;
        lb = a[i].first;
        lr = a[i].first;
      }
    }
  } else {
    int lb = -1;
    int lr = -1;
    for (int i = 0; i <= gi[0]; i++) {
      if (a[i].second == 'B') {
        if (lb == -1) {
          lb = a[i].first;
        } else {
          ans += a[i].first - lb;
          lb = a[i].first;
        }
      } else if (a[i].second == 'R') {
        if (lr == -1) {
          lr = a[i].first;
        } else {
          ans += a[i].first - lr;
          lr = a[i].first;
        }
      } else {
        assert(a[i].second == 'G');
        if (lr != -1) {
          ans += a[i].first - lr;
        }
        if (lb != -1) {
          ans += a[i].first - lb;
        }
      }
    }
    lb = a[gi.back()].first;
    lr = a[gi.back()].first;
    for (int i = gi.back() + 1; i < (int)a.size(); i++) {
      if (a[i].second == 'B') {
        if (lb == -1) {
          lb = a[i].first;
        } else {
          ans += a[i].first - lb;
          lb = a[i].first;
        }
      } else if (a[i].second == 'R') {
        if (lr == -1) {
          lr = a[i].first;
        } else {
          ans += a[i].first - lr;
          lr = a[i].first;
        }
      }
    }
  }
  cout << ans;
}
