local n = io.read("*n", "*l")
local t = {}
for i = 1, 2 * n do
  local str = io.read()
  local tp, num = str:match("(%w) (%d+)")
  num = tonumber(num)
  if tp == "B" then num = num + n end
  t[i] = num
end
local curw, curb = 1, n + 1
local len = 0
for i = 1, 2 * n do
  for j = 1, #t do
    if t[j] == curw or t[j] == curb then
      len = len + j - 1
      if t[j] == curw then curw = curw + 1 else curb = curb + 1 end
      table.remove(t, j)
      break
    end
  end
end
print(len)
