import sys

input=sys.stdin.readline



def runLength(s):

    a = []

    for c in s:

        if len(a)==0 or a[-1][0]!=c:

            a.append([c,1])

        else:

            a[-1][1] += 1

    return a



def main():

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

    S = input().strip()

    ans = 0

    for i,c in enumerate(S):

        if c == "L":

            if i > 0 and S[i-1] == "L":

                ans += 1

        if c == "R":

            if i < N-1 and S[i+1] == "R":

                ans += 1

    A = runLength(S)

    A.sort(key=lambda x:x[1], reverse=True)

    for i in range(K):

        if i < len(A):

            ans += 2

            if ans >= N:

                break

    if ans >= N:

        ans = N-1

    print(ans)



if __name__ == '__main__':

    main()
import sys

input=sys.stdin.readline



def main():

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

    S = input().strip()

    ans = 0

    for i,c in enumerate(S):

        if c == "L":

            if i > 0 and S[i-1] == "L":

                ans += 1

        if c == "R":

            if i < N-1 and S[i+1] == "R":

                ans += 1

    ans += K*2

    if ans >= N:

        ans = N-1

    print(ans)



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline


def runLength(s):
    a = []
    for c in s:
        if len(a) == 0 or a[-1][0] != c:
            a.append([c, 1])
        else:
            a[-1][1] += 1
    return a


def main():
    N, K = list(map(int, input().split()))
    S = input().strip()
    ans = 0
    for i, c in enumerate(S):
        if c == "L":
            if i > 0 and S[i - 1] == "L":
                ans += 1
        if c == "R":
            if i < N - 1 and S[i + 1] == "R":
                ans += 1
    A = runLength(S)
    A.sort(key=lambda x: x[1], reverse=True)
    for i in range(K):
        if i < len(A):
            ans += 2
            if ans >= N:
                break
    if ans >= N:
        ans = N - 1
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N, K = list(map(int, input().split()))
    S = input().strip()
    ans = 0
    for i, c in enumerate(S):
        if c == "L":
            if i > 0 and S[i - 1] == "L":
                ans += 1
        if c == "R":
            if i < N - 1 and S[i + 1] == "R":
                ans += 1
    ans += K * 2
    if ans >= N:
        ans = N - 1
    print(ans)


if __name__ == "__main__":
    main()

- - -def runLength(s): -    a = [] -    for c in s: -        if len(a) == 0 or a[-1][0] != c: -            a.append([c, 1]) -        else: -            a[-1][1] += 1 -    return a -    A = runLength(S) -    A.sort(key=lambda x: x[1], reverse=True) -    for i in range(K): -        if i < len(A): -            ans += 2 -            if ans >= N: -                break +    ans += K * 2