def slove():

    import sys

    input = sys.stdin.readline

    n, k = list(map(int, input().rstrip('\n').split()))

    s = str(input().rstrip('\n'))

    c = 0

    cl = 0

    mcl = 0

    cr = 0

    mcr = 0

    for i in range(n):

        if i != 0:

            if s[i] != s[i-1]:

                c += 1

                

        if s[i] == "R":

            cr += 1

            mcl += max((cl - 1), 0)

            cl = 0

        else:

            cl += 1

            mcr += max((cr - 1), 0)

            cr = 0



        if i == n - 1:

            mcl += max((cl - 1), 0)

            mcr += max((cr - 1), 0)



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





if __name__ == '__main__':

    slove()

import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n, k = list(map(int, input().rstrip('\n').split()))

    s = str(input().rstrip('\n'))

    ls = []

    cnt = 1

    for i in range(1, n):

        if s[i] != s[i-1]:

            ls.append(cnt-1)

            cnt = 1

        else:

            cnt += 1

    ls.append(cnt-1)

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





if __name__ == '__main__':

    solve()

def slove():
    import sys

    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip("\n").split()))
    s = str(input().rstrip("\n"))
    c = 0
    cl = 0
    mcl = 0
    cr = 0
    mcr = 0
    for i in range(n):
        if i != 0:
            if s[i] != s[i - 1]:
                c += 1
        if s[i] == "R":
            cr += 1
            mcl += max((cl - 1), 0)
            cl = 0
        else:
            cl += 1
            mcr += max((cr - 1), 0)
            cr = 0
        if i == n - 1:
            mcl += max((cl - 1), 0)
            mcr += max((cr - 1), 0)
    print((min(mcl + mcr + k * 2, n - 1)))


if __name__ == "__main__":
    slove()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n, k = list(map(int, input().rstrip("\n").split()))
    s = str(input().rstrip("\n"))
    ls = []
    cnt = 1
    for i in range(1, n):
        if s[i] != s[i - 1]:
            ls.append(cnt - 1)
            cnt = 1
        else:
            cnt += 1
    ls.append(cnt - 1)
    print((min(n - 1, sum(ls) + k * 2)))


if __name__ == "__main__":
    solve()

-def slove(): -    import sys +import sys + +def solve(): +    mod = 10**9 + 7 -    c = 0 -    cl = 0 -    mcl = 0 -    cr = 0 -    mcr = 0 -    for i in range(n): -        if i != 0: -            if s[i] != s[i - 1]: -                c += 1 -        if s[i] == "R": -            cr += 1 -            mcl += max((cl - 1), 0) -            cl = 0 +    ls = [] +    cnt = 1 +    for i in range(1, n): +        if s[i] != s[i - 1]: +            ls.append(cnt - 1) +            cnt = 1 -            cl += 1 -            mcr += max((cr - 1), 0) -            cr = 0 -        if i == n - 1: -            mcl += max((cl - 1), 0) -            mcr += max((cr - 1), 0) -    print((min(mcl + mcr + k * 2, n - 1))) +            cnt += 1 +    ls.append(cnt - 1) +    print((min(n - 1, sum(ls) + k * 2))) -    slove() +    solve()