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

s = eval(input())

t = tuple([1 if x == 'L' else 0 for x in s])



x = t[0]

region_count = 1

for tt in t:

    if tt ^ x == 1:

        region_count += 1

        x ^= 1



print((n - max(1, region_count - k * 2)))

# https://drken1215.hatenablog.com/entry/2020/05/16/005300



def main():

    from itertools import tee



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

    S = eval(input())



    s1, s2 = tee(S, 2)

    next(s2)



    cnt = 0

    for c1, c2 in zip(s1, s2):

        if c1 != c2:

            cnt += 1



    ans = N - 1 - max(cnt - K * 2, 0)



    print(ans)





if __name__ == '__main__':

    main()

n, k = list(map(int, input().split()))
s = eval(input())
t = tuple([1 if x == "L" else 0 for x in s])
x = t[0]
region_count = 1
for tt in t:
    if tt ^ x == 1:
        region_count += 1
        x ^= 1
print((n - max(1, region_count - k * 2)))

# https://drken1215.hatenablog.com/entry/2020/05/16/005300
def main():
    from itertools import tee

    N, K = list(map(int, input().split()))
    S = eval(input())
    s1, s2 = tee(S, 2)
    next(s2)
    cnt = 0
    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            cnt += 1
    ans = N - 1 - max(cnt - K * 2, 0)
    print(ans)


if __name__ == "__main__":
    main()

-n, k = list(map(int, input().split())) -s = eval(input()) -t = tuple([1 if x == "L" else 0 for x in s]) -x = t[0] -region_count = 1 -for tt in t: -    if tt ^ x == 1: -        region_count += 1 -        x ^= 1 -print((n - max(1, region_count - k * 2))) +# https://drken1215.hatenablog.com/entry/2020/05/16/005300 +def main(): +    from itertools import tee + +    N, K = list(map(int, input().split())) +    S = eval(input()) +    s1, s2 = tee(S, 2) +    next(s2) +    cnt = 0 +    for c1, c2 in zip(s1, s2): +        if c1 != c2: +            cnt += 1 +    ans = N - 1 - max(cnt - K * 2, 0) +    print(ans) + + +if __name__ == "__main__": +    main()