n, s = gets.chomp.split
n = n.to_i
arr = []
s.split("").each_with_index{|c, i| arr << i if c == "B"}

max = 0
if arr.length != 0
    arr2 = []
    prev = arr[0]
    temp = [prev]
    arr[1..-1].each{|x|
        if x == prev + 1
            temp << x
        else
            arr2 << temp
            temp = [x]
        end
        prev = x
    }
    arr2 << temp

    arr2.each{|ar|
        next if ar[0] == 0
        next if ar[-1] == n - 1
    
        dame = false
        (ar[0] - 2).downto(0){|i|
            case s[i]
            when "B"
                dame = true
                break
            when "."
                break
            end
        }
        next if dame
    
        dame = false
        (ar[-1] + 2).upto(n - 1){|i|
            case s[i]
            when "B"
                dame = true
                break
            when "."
                break
            end
        }
        next if dame
    
        next if s[ar[0] - 1] == "." && s[ar[-1] + 1] == "."
        next if s[ar[0] - 1] == "W" && s[ar[-1] + 1] == "W"
        max = ar[-1] - ar[0] + 1 if max < ar[-1] - ar[0] + 1
    }
end
puts max
