let n = Int(readLine()!)! var s = readLine()!.map{String($0)} s.append("A") var cnt = 0, f = true for i in 0...(n-2){ if s[i] == "A"{ cnt += 1 }else{ if f && s[i+1] == "B"{ cnt += 1 f = false }else if s[i+1] == "A" && s[i+2] == "A"{ cnt += 1 } } } print(cnt)