import sys



input = sys.stdin.readline



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

rs = lambda: input().rstrip()

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

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]





def rle(s):

    import itertools

    return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])





n, k = ril()

s = rs()

s = rle(s)

m = len(s)

if m <= 2 * k:

    print((n - 1))

else:

    print((n - m + 2 * k))
import sys



input = sys.stdin.readline



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

rs = lambda: input().rstrip()

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

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]



n, k = ril()

s = rs()

m = 1

for c0, c1 in zip(s, s[1:]):

    if c0 != c1:

        m += 1

if m <= 2 * k:

    print((n - 1))

else:

    print((n - m + 2 * k))
import sys

input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def rle(s):
    import itertools

    return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])


n, k = ril()
s = rs()
s = rle(s)
m = len(s)
if m <= 2 * k:
    print((n - 1))
else:
    print((n - m + 2 * k))

import sys

input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
s = rs()
m = 1
for c0, c1 in zip(s, s[1:]):
    if c0 != c1:
        m += 1
if m <= 2 * k:
    print((n - 1))
else:
    print((n - m + 2 * k))

- - -def rle(s): -    import itertools - -    return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)]) - - -s = rle(s) -m = len(s) +m = 1 +for c0, c1 in zip(s, s[1:]): +    if c0 != c1: +        m += 1