n, k = list(map(int, input().split()))

s = list(eval(input()))

h = 0



for i in range(1, len(s)):

    if s[i-1] == s[i]:

        h += 1

        

print((min(n-1, h+k*2)))

def main():

    N, K = list(map(int,input().split()))

    S = eval(input())



    #幸せな人の数

    h = 0 

    s1 = 'S'

    for s in S:

        if s == s1:

            h += 1

        s1 = s



    print((min(h+(K*2) ,N-1)))



if __name__ == '__main__':

    main()
n, k = list(map(int, input().split()))
s = list(eval(input()))
h = 0
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        h += 1
print((min(n - 1, h + k * 2)))

def main():
    N, K = list(map(int, input().split()))
    S = eval(input())
    # 幸せな人の数
    h = 0
    s1 = "S"
    for s in S:
        if s == s1:
            h += 1
        s1 = s
    print((min(h + (K * 2), N - 1)))


if __name__ == "__main__":
    main()

-n, k = list(map(int, input().split())) -s = list(eval(input())) -h = 0 -for i in range(1, len(s)): -    if s[i - 1] == s[i]: -        h += 1 -print((min(n - 1, h + k * 2))) +def main(): +    N, K = list(map(int, input().split())) +    S = eval(input()) +    # 幸せな人の数 +    h = 0 +    s1 = "S" +    for s in S: +        if s == s1: +            h += 1 +        s1 = s +    print((min(h + (K * 2), N - 1))) + + +if __name__ == "__main__": +    main()