#include<bits/stdc++.h>
using namespace std;
const int N = 2005;

int n, a[2*N], c[2*N], id[2][N], sum[2][N][2*N], dt[N][N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) {
		char T[2];
		scanf("%s%d",T,&a[i]);
		c[i] = (T[0] == 'B');
		id[c[i]][a[i]] = i;
		for(int j=a[i];j<=n;j++) {
			sum[c[i]][j][i]++;
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=2*n;j++) {
			sum[0][i][j] += sum[0][i][j-1];
			sum[1][i][j] += sum[1][i][j-1];
		}
	}
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			int A = id[0][i], B = id[1][j];
			if(i == 0 && j == 0) continue;
			else if(i == 0) {
				dt[i][j] = dt[i][j-1] + B-1 - sum[0][i][B] - sum[1][j-1][B];
			}
			else if(j == 0) {
				dt[i][j] = dt[i-1][j] + A-1 - sum[0][i-1][A] - sum[1][j][A];
			}
			else {
				dt[i][j] = min(dt[i-1][j] + A-1 - sum[0][i-1][A] - sum[1][j][A], dt[i][j-1] + B-1 - sum[0][i][B] - sum[1][j-1][B]);
			}
		}
	}
	printf("%d\n",dt[n][n]);
}
