#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=2010;
char s[2];
int f[N][N],s1[N+N][N],s2[N+N][N],p1[N],p2[N];
int main() {
    int n;
    cin>>n;
    memset(f,127/3,sizeof(f));
    f[0][0]=0;
    for(int i=1;i<=n+n;i++) {
	int x;
	scanf("%s%d",s,&x);
	if(s[0]=='B') s1[i][x]=1,p1[x]=i;
	else s2[i][x]=1,p2[x]=i;
	for(int j=n;j;j--) {
	    s1[i][j]+=s1[i-1][j]+s1[i][j+1]-s1[i-1][j+1];
	    s2[i][j]+=s2[i-1][j]+s2[i][j+1]-s2[i-1][j+1];
	}
    }
    for(int i=0;i<=n;i++)
	for(int j=0;j<=n;j++) {
	    if(i) f[i][j]=min(f[i][j],f[i-1][j]+s1[p1[i]][i+1]+s2[p1[i]][j+1]);
	    if(j) f[i][j]=min(f[i][j],f[i][j-1]+s1[p2[j]][i+1]+s2[p2[j]][j+1]);
	}
    cout<<f[n][n];
    return 0;
}