import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

class Ball{
	char color;
	int value;
	this(char c, int v){
		this.color = c;
		this.value = v;
		debug writeln(c, "|", v);
		}
	}

void main(){
	auto n = read.to!int;
	Ball[] balls;
	foreach(i; 0 .. n * 2){
		char c = read.to!(char[])[0];
		int v = read.to!int - 1;
		balls ~= new Ball(c, v);
		}
	
	bool[][] ws; // ws[ia][ib]: 白ibは白iaよりも前にある
	bool[][] bs; // bs[ja][jb]: 黒jbは黒jaよりも前にある
	bool[][] ps; // ps[i][j]: 黒jは白iよりも前にある
	bool[] wx, bx; // wx[i]: 白iは登場済み、 bx[j]: 黒jは登場済み
	
	ws.length = n; foreach(i; 0 .. n) ws[i].length = n;
	bs.length = n; foreach(j; 0 .. n) bs[j].length = n;
	ps.length = n; foreach(i; 0 .. n) ps[i].length = n;
	wx.length = n, bx.length = n;
	
	foreach(ball; balls){
		if(ball.color == 'B'){
			int j = ball.value;
			foreach(ja; 0 .. n) bs[ja][j] = !bx[ja];
			foreach(jb; 0 .. n) bs[j][jb] = bx[jb];
			foreach(i; 0 .. n) ps[i][j] = !wx[i];
			bx[j] = 1;
			}
		else{
			int i = ball.value;
			foreach(ia; 0 .. n) ws[ia][i] = !wx[ia];
			foreach(ib; 0 .. n) ws[i][ib] = wx[ib];
			foreach(j; 0 .. n) ps[i][j] = bx[j];
			wx[i] = 1;
			}
		}
	
	debug writeln("ws"), writeln(ws);
	debug writeln("bs"), writeln(bs);
	debug writeln("ps"), writeln(ps);
	debug writeln("wx"), writeln(wx);
	debug writeln("bx"), writeln(bx);
	
	int[] wcnt; // wcnt[i]: 白iより前にある白i以上の個数
	int[] bcnt; // bcnt[j]: 黒jより前にある黒j以上の個数
	int[][] pcnt; // pcnt[i][j]: 白iより前にある黒j以上の個数
	
	wcnt.length = n, bcnt.length = n;
	pcnt.length = n; foreach(i; 0 .. n) pcnt[i].length = n;
	
	foreach(i; 0 .. n){
		int cnt = 0;
		foreach(ib; i + 1 .. n) if(ws[i][ib]) cnt += 1;
		wcnt[i] = cnt;
		}
	foreach(j; 0 .. n){
		int cnt = 0;
		foreach(jb; j + 1 .. n) if(bs[j][jb]) cnt += 1;
		bcnt[j] = cnt;
		}
	foreach(i; 0 .. n){
		foreach_reverse(j; 0 .. n){
			if(j == n - 1) pcnt[i][j] = (ps[i][j]? 1: 0);
			else pcnt[i][j] = pcnt[i][j + 1] + (ps[i][j]? 1: 0);
			}
		}
	
	debug writeln("wcnt"), writeln(wcnt);
	debug writeln("bcnt"), writeln(bcnt);
	debug writeln("pcnt"), writeln(pcnt);
	
	int[][] wov; // wov[i][j]: 白iより前にある白i以上と黒j以上の個数
	int[][] bov; // bov[i][j]: 黒jより前にある白i以上と黒j以上の個数
	
	wov.length = n + 2; foreach(i; 0 .. n + 2) wov[i].length = n + 2;
	bov.length = n + 2; foreach(j; 0 .. n + 2) bov[j].length = n + 2;
	
	foreach(i; 0 .. n){
		foreach(j; 0 .. n){
			wov[i][j] = wcnt[i] + pcnt[i][j];
			bov[i][j] = bcnt[j] + pcnt[i][j];
			}
		}
	foreach(i; 0 .. n) wov[i][n] = wcnt[i], wov[i][n + 1] = wcnt[i];
	foreach(j; 0 .. n) bov[n][j] = bcnt[j], bov[n + 1][j] = bcnt[j];
	
	debug writeln("wov"), writeln(wov);
	debug writeln("bov"), writeln(bov);
	
	int[][] ans; // ans[i][j]: 先頭に白i個黒j個が正しい順で並んでいる状態にするのに必要な手数
	ans.length = n + 1; foreach(i; 0 .. n + 1) ans[i].length = n + 1;
	
	foreach(i; 0 .. n + 1){
		foreach(j; 0 .. n + 1){
			int a = int.max;
			if(i > 0) a = min(a, ans[i - 1][j] + 1 + wov[i][j + 1]);
			if(j > 0) a = min(a, ans[i][j - 1] + 1 + bov[i + 1][j]);
			if(i == 0 && j == 0) a = 0;
			
			ans[i][j] = a;
			}
		}
	
	debug writeln("ans"), writeln(ans);
	
	(ans[n - 1][n - 1] - 1).writeln;
	
	}