// Copyright (C) 2018 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int n = input<int>();

    vector<pair<bool, int>> a(2 * n);

    for (int i = 0; i != 2 * n; ++i) {
        a[i].first  = (input<char>() == 'W');
        a[i].second = input<int>();
    }

    
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));

    vector<int> index_of0(n + 1, -1), index_of1(n + 1, -1);
    for (int i = 0; i != 2 * n; ++i)
        (a[i].first == 0 ? index_of0 : index_of1)[a[i].second] = i;

    vector<vector<int>> pref_counts0(2 * n, vector<int>(n + 1)), pref_counts1(2 * n, vector<int>(n + 1));
    for (int i = 0; i != 2 * n; ++i)
        for (int j = 0; j <= n; ++j) {
            pref_counts0[i][j] = 0;

            if (i)
                pref_counts0[i][j] += pref_counts0[i - 1][j];
            if (a[i].first == 0 and a[i].second <= j)
                ++pref_counts0[i][j];
        }

    for (int i = 0; i != 2 * n; ++i)
        for (int j = 0; j <= n; ++j) {
            pref_counts1[i][j] = 0;

            if (i)
                pref_counts1[i][j] += pref_counts1[i - 1][j];
            if (a[i].first == 1 and a[i].second <= j)
                ++pref_counts1[i][j];
        }

    
    auto count = [&](int i, int j, bool tp, int vl) {
        int ind = (tp == 0 ? index_of0 : index_of1)[vl];

        int ans = ind;
        if (ind > 0) {
            ans -= pref_counts0[ind - 1][i];
            ans -= pref_counts1[ind - 1][j];
        }
        return ans;
    };
    
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
            if (i + j == 0)
                dp[i][j] = 0;
            else {
                dp[i][j] = TYPEMAX(int);
                if (i)
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + (int)count(i, j, 0, i));
                if (j)
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + (int)count(i, j, 1, j));
            }


    cout << dp.back().back() << "\n";
    
    return 0;
}


Measured memory_bytes: 78976