#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

int n, w[N], b[N], d[N][N], dw[2 * N][N], db[2 * N][N];
char c;
int main()
{
	int i, j, t, t1, t2;
	cin >> n;
	for (i = 1; i <= 2 * n; i++) {
		scanf("%s %d", &c, &t);
		if (c == 'W') w[t] = i;
		else b[t] = i;
		for (j = 1; j <= n; j++) {
			dw[i][j] = dw[i - 1][j], db[i][j] = db[i - 1][j];
			if (c == 'W') dw[i][j] += (t >= j);
			else db[i][j] += (t >= j);
		}
	}
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n; j++) {
			t1 = i > 0 ? d[i - 1][j] + dw[w[i]][i + 1] + db[w[i]][j + 1] : 1e9;
			t2 = j > 0 ? d[i][j - 1] + dw[b[j]][i + 1] + db[b[j]][j + 1] : 1e9;
			d[i][j] = min(t1, t2);
			d[0][0] = 0;
		}
	}
	cout << d[n][n];
    return 0;
}