def solve(string):

    n, k, s = string.split()

    k = int(k)

    ans = change = 0

    for s0, s1 in zip(s, s[1:]):

        if s0 == s1:

            ans += 1

        else:

            change += 1

    return str(ans + min(2 * k, change))





if __name__ == '__main__':

    print((solve('\n'.join([eval(input()), eval(input())]))))

def solve(string):

    n, k, s = string.split()

    n, k = list(map(int, [n, k]))

    ans = n - 1 - s.count("RL") - s.count("LR")

    return str(min(ans + 2 * k, n - 1))





if __name__ == '__main__':

    print((solve('\n'.join([eval(input()), eval(input())]))))

def solve(string):
    n, k, s = string.split()
    k = int(k)
    ans = change = 0
    for s0, s1 in zip(s, s[1:]):
        if s0 == s1:
            ans += 1
        else:
            change += 1
    return str(ans + min(2 * k, change))


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

def solve(string):
    n, k, s = string.split()
    n, k = list(map(int, [n, k]))
    ans = n - 1 - s.count("RL") - s.count("LR")
    return str(min(ans + 2 * k, n - 1))


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

-    k = int(k) -    ans = change = 0 -    for s0, s1 in zip(s, s[1:]): -        if s0 == s1: -            ans += 1 -        else: -            change += 1 -    return str(ans + min(2 * k, change)) +    n, k = list(map(int, [n, k])) +    ans = n - 1 - s.count("RL") - s.count("LR") +    return str(min(ans + 2 * k, n - 1))