#include<bits/stdc++.h>
#define MAX 2005
using namespace std;

bool b[2][MAX];
int dp[MAX][MAX], s[2][MAX][MAX];

int main(){
  int n, d;
  char c;
  scanf("%d", &n);
  for(int i = 0; i < n*2; i++){
    cin >> c >> d;
    bool t = (c == 'B');
    int k = 0;
    b[t][--d] = true;
    for(int j = d+1; j < n; j++) k += b[t][j];
    s[t][d][n] = k;
    for(int j = n-1; j >= 0; j--) s[t][d][j] = s[t][d][j+1] + b[!t][j];
  }
  for(int i = 1; i <= n; i++){
    dp[0][i] = dp[0][i-1] + s[1][i-1][0];
    dp[i][0] = dp[i-1][0] + s[0][i-1][0]; 
  }
  for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++)
    dp[i][j] = min(dp[i-1][j] + s[0][i-1][j], dp[i][j-1] + s[1][j-1][i]);
  printf("%d\n", dp[n][n]);
}