import sys

input = sys.stdin.readline

sys.setrecursionlimit(1000000)

from collections import deque

def getN():

    return int(eval(input()))

def getList():

    return list(map(int, input().split()))

import math



n, k = getList()



s = input().strip()

s = s



state = "X"

cur_seq = 0

seq_nums = []

n_separate = 0





for c in s:

    # print(c, state == c)

    if state == c:

        cur_seq += 1

    else:

        state = c

        seq_nums.append(cur_seq)

        cur_seq = 1

        n_separate += 1





# print(n_separate)

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



import sys

from collections import defaultdict, deque, Counter

import math

 

# import copy

from bisect import bisect_left, bisect_right

# import heapq

 

# sys.setrecursionlimit(1000000)

 

# input aliases

input = sys.stdin.readline

 

getS = lambda: input().strip()

getN = lambda: int(eval(input()))

getList = lambda: list(map(int, input().split()))

getZList = lambda: [int(x) - 1 for x in input().split()]

 

INF = 10 ** 20

MOD = 10**9 + 7

divide = lambda x: pow(x, MOD-2, MOD)



def getmoji(k):

    return chr(ord("a") + k)



def main():

    n, k = getList()

    s = getS()



    ko, fuko = 0, 0

    for i, j in zip(s, s[1:]):

        if i == j:

            ko += 1

        else:

            fuko += 1

    print((ko + min(k*2, fuko)))





if __name__ == "__main__":

    main()

   
import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque


def getN():
    return int(eval(input()))


def getList():
    return list(map(int, input().split()))


import math

n, k = getList()
s = input().strip()
s = s
state = "X"
cur_seq = 0
seq_nums = []
n_separate = 0
for c in s:
    # print(c, state == c)
    if state == c:
        cur_seq += 1
    else:
        state = c
        seq_nums.append(cur_seq)
        cur_seq = 1
        n_separate += 1
# print(n_separate)
print((min(n - n_separate + 2 * k, n - 1)))

import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right

# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)


def getmoji(k):
    return chr(ord("a") + k)


def main():
    n, k = getList()
    s = getS()
    ko, fuko = 0, 0
    for i, j in zip(s, s[1:]):
        if i == j:
            ko += 1
        else:
            fuko += 1
    print((ko + min(k * 2, fuko)))


if __name__ == "__main__":
    main()

+from collections import defaultdict, deque, Counter +import math +# import copy +from bisect import bisect_left, bisect_right + +# import heapq +# sys.setrecursionlimit(1000000) +# input aliases -sys.setrecursionlimit(1000000) -from collections import deque +getS = lambda: input().strip() +getN = lambda: int(eval(input())) +getList = lambda: list(map(int, input().split())) +getZList = lambda: [int(x) - 1 for x in input().split()] +INF = 10**20 +MOD = 10**9 + 7 +divide = lambda x: pow(x, MOD - 2, MOD) -def getN(): -    return int(eval(input())) +def getmoji(k): +    return chr(ord("a") + k) -def getList(): -    return list(map(int, input().split())) +def main(): +    n, k = getList() +    s = getS() +    ko, fuko = 0, 0 +    for i, j in zip(s, s[1:]): +        if i == j: +            ko += 1 +        else: +            fuko += 1 +    print((ko + min(k * 2, fuko))) -import math - -n, k = getList() -s = input().strip() -s = s -state = "X" -cur_seq = 0 -seq_nums = [] -n_separate = 0 -for c in s: -    # print(c, state == c) -    if state == c: -        cur_seq += 1 -    else: -        state = c -        seq_nums.append(cur_seq) -        cur_seq = 1 -        n_separate += 1 -# print(n_separate) -print((min(n - n_separate + 2 * k, n - 1))) +if __name__ == "__main__": +    main()