#D-Face Produces Unhappiness

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

S = str(eval(input()))



def count_LRorRL(l):

    ans = 0

    l_index = [l[i]+l[i+1] for i in range(0,N-1)]

    ans += l_index.count('LR')

    ans += l_index.count('RL')

    return ans



def count_LLorRR(l):

    ans = 0

    l_index = [l[i]+l[i+1] for i in range(0,N-1)]

    ans += l_index.count('LL')

    ans += l_index.count('RR')

    return ans

  

if count_LRorRL(S) > 2*K:

    print((count_LLorRR(S)+2*K))

else:

    print((count_LLorRR(S)+count_LRorRL(S)))

#D-Face Produces Unhappiness

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

S = str(eval(input()))

S_index = [S[i]+S[i+1] for i in range(0,N-1)]



count_LRorRL =0

count_LRorRL += S_index.count('LR')

count_LRorRL += S_index.count('RL')



count_LLorRR = 0

count_LLorRR += S_index.count('LL')

count_LLorRR += S_index.count('RR')



if count_LRorRL > 2*K:

    print((count_LLorRR+2*K))

else:

    print((count_LLorRR+count_LRorRL))
# D-Face Produces Unhappiness
N, K = list(map(int, input().split()))
S = str(eval(input()))


def count_LRorRL(l):
    ans = 0
    l_index = [l[i] + l[i + 1] for i in range(0, N - 1)]
    ans += l_index.count("LR")
    ans += l_index.count("RL")
    return ans


def count_LLorRR(l):
    ans = 0
    l_index = [l[i] + l[i + 1] for i in range(0, N - 1)]
    ans += l_index.count("LL")
    ans += l_index.count("RR")
    return ans


if count_LRorRL(S) > 2 * K:
    print((count_LLorRR(S) + 2 * K))
else:
    print((count_LLorRR(S) + count_LRorRL(S)))

# D-Face Produces Unhappiness
N, K = list(map(int, input().split()))
S = str(eval(input()))
S_index = [S[i] + S[i + 1] for i in range(0, N - 1)]
count_LRorRL = 0
count_LRorRL += S_index.count("LR")
count_LRorRL += S_index.count("RL")
count_LLorRR = 0
count_LLorRR += S_index.count("LL")
count_LLorRR += S_index.count("RR")
if count_LRorRL > 2 * K:
    print((count_LLorRR + 2 * K))
else:
    print((count_LLorRR + count_LRorRL))

- - -def count_LRorRL(l): -    ans = 0 -    l_index = [l[i] + l[i + 1] for i in range(0, N - 1)] -    ans += l_index.count("LR") -    ans += l_index.count("RL") -    return ans - - -def count_LLorRR(l): -    ans = 0 -    l_index = [l[i] + l[i + 1] for i in range(0, N - 1)] -    ans += l_index.count("LL") -    ans += l_index.count("RR") -    return ans - - -if count_LRorRL(S) > 2 * K: -    print((count_LLorRR(S) + 2 * K)) +S_index = [S[i] + S[i + 1] for i in range(0, N - 1)] +count_LRorRL = 0 +count_LRorRL += S_index.count("LR") +count_LRorRL += S_index.count("RL") +count_LLorRR = 0 +count_LLorRR += S_index.count("LL") +count_LLorRR += S_index.count("RR") +if count_LRorRL > 2 * K: +    print((count_LLorRR + 2 * K)) -    print((count_LLorRR(S) + count_LRorRL(S))) +    print((count_LLorRR + count_LRorRL))