if __name__ == '__main__':

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

    S = eval(input())

    # ans = 0

    # for i in range(N-1):

    #     if S[i] == S[i+1]:

    #         ans += 1

    ans = N - 1 - S.count('LR') - S.count('RL')

    ans = min(N-1, ans+K*2)

    print(ans)

import sys



if __name__ == '__main__':

    N, K = list(map(int, sys.stdin.readline().split()))

    S = sys.stdin.readline()

    # ans = 0

    # for i in range(N-1):

    #     if S[i] == S[i+1]:

    #         ans += 1

    ans = N - 1 - S.count('LR') - S.count('RL')

    ans = min(N-1, ans+K*2)

    print(ans)

if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    S = eval(input())
    # ans = 0
    # for i in range(N-1):
    #     if S[i] == S[i+1]:
    #         ans += 1
    ans = N - 1 - S.count("LR") - S.count("RL")
    ans = min(N - 1, ans + K * 2)
    print(ans)

import sys

if __name__ == "__main__":
    N, K = list(map(int, sys.stdin.readline().split()))
    S = sys.stdin.readline()
    # ans = 0
    # for i in range(N-1):
    #     if S[i] == S[i+1]:
    #         ans += 1
    ans = N - 1 - S.count("LR") - S.count("RL")
    ans = min(N - 1, ans + K * 2)
    print(ans)

+import sys + -    N, K = list(map(int, input().split())) -    S = eval(input()) +    N, K = list(map(int, sys.stdin.readline().split())) +    S = sys.stdin.readline()