#include <cstring>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int col[2*n], val[2*n];
    int pos[2][n];
    for (int i = 0; i < 2*n; i++) {
        char c; int a; cin >> c >> a;
        col[i] = c == 'B';
        val[i] = a-1;
        pos[c == 'B'][a-1] = i;
    }

    int cost[2][n+1][2*n];
    for (int c = 0; c < 2; c++) 
        for (int v = 0; v <= n; v++) {
            cost[c][v][0] = 0;
            for (int j = 1; j < 2*n; j++)
                cost[c][v][j] = cost[c][v][j-1] + int(col[j-1] == c && val[j-1] >= v);
        }

    int dp[n+1][n+1];
    memset(dp, 0, sizeof dp);
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 && j == 0) { dp[0][0] = 0; continue; }
            int val = 1<<30;
            if (i > 0) {
                const int p = pos[0][i-1];
                val = min(val, dp[i-1][j] + cost[0][i][p] + cost[1][j][p]);
            }
            if (j > 0) {
                const int q = pos[1][j-1];
                val = min(val, dp[i][j-1] + cost[0][i][q] + cost[1][j][q]);
            }
            dp[i][j] = val;
        }
    }
    cout << dp[n][n] << endl;
}
