def main():

    length, operation = list(map(int, input().split()))

    direction = list(eval(input()))

    before = ""

    inverse = {"L": "R", "R": "L"}

    change = 0

    section = 0

    answer = 0

    for i in range(length):

        if not before == direction[i]:

            before = direction[i]

            section += 1

            if section % 2:

                change += 1

        if section % 2 == 0 and change <= operation:

            direction[i] = inverse[direction[i]]

    for i in range(1, length):

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

            answer += 1

    print(answer)





if __name__ == '__main__':

    main()



def main():

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

    s = list("*" + eval(input()) + "*")

    count = 0

    for i in range(1, n + 1):

        if (s[i] == s[i - 1] == "L") or (s[i] == s[i + 1] == "R"):

            count += 1

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





if __name__ == '__main__':

    main()



def main():
    length, operation = list(map(int, input().split()))
    direction = list(eval(input()))
    before = ""
    inverse = {"L": "R", "R": "L"}
    change = 0
    section = 0
    answer = 0
    for i in range(length):
        if not before == direction[i]:
            before = direction[i]
            section += 1
            if section % 2:
                change += 1
        if section % 2 == 0 and change <= operation:
            direction[i] = inverse[direction[i]]
    for i in range(1, length):
        if direction[i] == direction[i - 1]:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()

def main():
    n, k = list(map(int, input().split()))
    s = list("*" + eval(input()) + "*")
    count = 0
    for i in range(1, n + 1):
        if (s[i] == s[i - 1] == "L") or (s[i] == s[i + 1] == "R"):
            count += 1
    print((min(count + 2 * k, n - 1)))


if __name__ == "__main__":
    main()

-    length, operation = list(map(int, input().split())) -    direction = list(eval(input())) -    before = "" -    inverse = {"L": "R", "R": "L"} -    change = 0 -    section = 0 -    answer = 0 -    for i in range(length): -        if not before == direction[i]: -            before = direction[i] -            section += 1 -            if section % 2: -                change += 1 -        if section % 2 == 0 and change <= operation: -            direction[i] = inverse[direction[i]] -    for i in range(1, length): -        if direction[i] == direction[i - 1]: -            answer += 1 -    print(answer) +    n, k = list(map(int, input().split())) +    s = list("*" + eval(input()) + "*") +    count = 0 +    for i in range(1, n + 1): +        if (s[i] == s[i - 1] == "L") or (s[i] == s[i + 1] == "R"): +            count += 1 +    print((min(count + 2 * k, n - 1)))