import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



def main():

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

    S = list(eval(input()))



    rev = False

    rev_count = 0

    for i in range(1,N):

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

            rev = False

        else:

            if not rev and rev_count < K:

                rev_count += 1

                rev = True



            if rev:

                S[i] = 'L' if S[i] == 'R' else 'R'





    ans = 0

    for i in range(1,N):

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

            ans += 1



    print(ans)





if __name__ == "__main__":

    main()

# 解説見た後に作ったやつ

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



def main():

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

    S = list(eval(input()))



    rev = False

    ans = 0

    rev_count = 0

    for i in range(1,N):

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

            ans += 1

            rev = False

        else:

            if not rev and rev_count < K:

                rev_count += 1

                rev = True



            if rev:

                S[i] = 'L' if S[i] == 'R' else 'R'

                ans += 1





    print(ans)





if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    N, K = list(map(int, input().split()))
    S = list(eval(input()))
    rev = False
    rev_count = 0
    for i in range(1, N):
        if S[i] == S[i - 1]:
            rev = False
        else:
            if not rev and rev_count < K:
                rev_count += 1
                rev = True
            if rev:
                S[i] = "L" if S[i] == "R" else "R"
    ans = 0
    for i in range(1, N):
        if S[i] == S[i - 1]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

# 解説見た後に作ったやつ
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    N, K = list(map(int, input().split()))
    S = list(eval(input()))
    rev = False
    ans = 0
    rev_count = 0
    for i in range(1, N):
        if S[i] == S[i - 1]:
            ans += 1
            rev = False
        else:
            if not rev and rev_count < K:
                rev_count += 1
                rev = True
            if rev:
                S[i] = "L" if S[i] == "R" else "R"
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

+# 解説見た後に作ったやつ +    ans = 0 +            ans += 1 -    ans = 0 -    for i in range(1, N): -        if S[i] == S[i - 1]: -            ans += 1 +                ans += 1