
Imports System.Console
Module Module1
    Dim ans As Integer
    Dim n As Integer
    Dim Wnum() As Integer
    Sub Main()
        n = ReadLine()
        Dim min As Integer = 2 * 10 ^ 5
        Dim s As String = ReadLine()
        ReDim Wnum(n)
        For i = 1 To n
            Dim w As Char = s.Substring(i - 1, 1)
            If w = "W" Then
                Wnum(i) = Wnum(i - 1) + 1
            Else
                Wnum(i) = Wnum(i - 1)
            End If
        Next
        For i = 1 To n
            Dim ww As Integer = Calc(i)
            If ww < min Then
                min = ww
            End If
        Next
        If Wnum(n) = n Then
            WriteLine("0")
        Else
            WriteLine(min)
        End If
    End Sub
    Function Calc(ByVal num As Integer)
        Dim ctoR, ctoW As Integer
        ctoR = Wnum(num)
        ctoW = (n - Wnum(n)) - (num - Wnum(num))
        If ctoR > ctoW Then
            Return ctoR
        Else
            Return ctoW
        End If
    End Function
End Module
