#include <bits/stdc++.h>
using namespace std;
#define MAXN 4000
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int B[MAXN+5][2005], W[MAXN+5][2005], f[2005][2005], w[MAXN+5], b[MAXN+5], n; string S;
int main()
{
	n = read(); for(rint i = 1, a; i <= n<<1; cin >> S, (S[0]=='W'?W:B)[i][a=read()]++, (S[0]=='W'?w:b)[a] = i, i++);
	for(rint i = 1, j; i <= n<<1; i++)
	{
		for(j = n; j; B[i][j] += B[i][j+1], W[i][j] += W[i][j+1], j--);
		for(j = n; j; B[i][j] += B[i-1][j], W[i][j] += W[i-1][j], j--);
	}	memset(f,0x3f,sizeof f), f[0][0] = 0;
	for(rint i = 0, j; i <= n; i++) for(j = 0; j <= n; j++)
		i<n ? f[i+1][j] = min(f[i+1][j],f[i][j]+B[b[i+1]-1][i+1]+W[b[i+1]-1][j+1]) : 0,
		j<n ? f[i][j+1] = min(f[i][j+1],f[i][j]+B[w[j+1]-1][i+1]+W[w[j+1]-1][j+1]) : 0; printf("%d\n",f[n][n]); return 0;
}