#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, ans, x[maxn], y[maxn], i, r, b, mxr, mxb, rr, bb;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", x + i);
    char c = getchar();
    while (c < 'A' || c > 'Z') c = getchar();
    if (c == 'R') y[i] = -1;
    if (c == 'B') y[i] = 1;
  }
  i = 1;
  while (i <= n && y[i]) {
    if (y[i] < 0) {
      if (r) ans += x[i] - x[r];
      r = i;
    }
    if (y[i] > 0) {
      if (b) ans += x[i] - x[b];
      b = i;
    }
    ++i;
  }
  if (i > n) {
    printf("%d\n", ans);
    return 0;
  }
  if (r) ans += x[i] - x[r];
  if (b) ans += x[i] - x[b];
  while (i <= n) {
    int j = i + 1;
    while (j <= n && y[j]) ++j;
    if (j > n) {
      r = b = i;
      for (int j = i + 1; j <= n; ++j) {
        if (y[j] < 0) ans += x[j] - x[r], r = j;
        if (y[j] > 0) ans += x[j] - x[b], b = j;
      }
      printf("%d\n", ans);
      return 0;
    }
    r = b = mxr = mxb = rr = bb = 0;
    for (int k = i + 1; k < j; ++k) {
      if (y[k] < 0) {
        if (r)
          mxr = max(mxr, x[k] - x[r]);
        else
          rr = k;
        r = k;
      }
      if (y[k] > 0) {
        if (b)
          mxb = max(mxb, x[k] - x[b]);
        else
          bb = k;
        b = k;
      }
    }
    if (!r) {
      if (!b)
        ans += x[j] - x[i];
      else
        ans += (x[j] - x[i] << 1) - max(mxb, max(x[bb] - x[i], x[j] - x[b]));
    } else {
      if (!b)
        ans += (x[j] - x[i] << 1) - max(mxr, max(x[rr] - x[i], x[j] - x[r]));
      else
        ans +=
            min(x[j] - x[i] << 1, (x[j] - x[i]) * 3 -
                                      max(mxr, max(x[rr] - x[i], x[j] - x[r])) -
                                      max(mxb, max(x[bb] - x[i], x[j] - x[b])));
    }
    i = j;
  }
}
