#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]



sys.setrecursionlimit(1000000)

mod = 1000000007



#A

def A():

    n = I()

    print((n**3))

    return



#B

def B():

    n = I()

    a = LI()

    b = LI()

    c = LI()

    ans = sum(b)

    for i in range(n-1):

        x = a[i]

        y = a[i+1]

        if y == x+1:

            ans += c[x-1]

    print(ans)

    return



#C

def C():

    n = I()

    b = LI()

    b.append(float("inf"))

    a = [min(b[i],b[i-1]) for i in range(n)]

    print((sum(a)))

    return



#D

def D():

    n,k = LI()

    a = S()

    ans = 0

    for i in range(n-1):

        if a[i] == a[i+1]:

            ans += 1

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

    return



#E

def E():

    def add(i):

        while i <= n:

            bit[i] += 1

            i += i&-i



    def sum(i):

        res = 0

        while i > 0:

            res += bit[i]

            i -= i&-i

        return res



    n = I()

    p = LI()

    r = [0]*n

    bit = [0]*(n+1)

    for i in range(n)[::-1]:

        r[i] = (n-i-1)-sum(p[i])

        add(p[i])

    print(r)

    l = [0]*n

    bit = [0]*(n+1)

    for i in range(n):

        l[i] = i-sum(p[i])

        add(p[i])

    print(l)



    return



#F

def F():

    n = I()

    s = LI()

    s.sort()

    s = s[::-1]

    if s[0] == s[1]:

        print("No")

        return

    a = [s[0]]

    j = 1

    s.append(0)

    q = deque()

    for _ in range(n):

        for i in range(1<<_):

            if a[i] > s[j]:

                a.append(s[j])

                j += 1

            else:

                q.append(a[i])

    print(a)

    return



#Solve

if __name__ == "__main__":

    D()

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from itertools import permutations

import sys

import math

import bisect

import random

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]



sys.setrecursionlimit(1000000)

mod = 1000000007



def solve():

    n,k = LI()

    s = eval(input())

    ans = 0

    for i in range(n-1):

        if s[i] == s[i+1]:

            ans += 1

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

    return



#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
    n = I()
    print((n**3))
    return


# B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n - 1):
        x = a[i]
        y = a[i + 1]
        if y == x + 1:
            ans += c[x - 1]
    print(ans)
    return


# C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i], b[i - 1]) for i in range(n)]
    print((sum(a)))
    return


# D
def D():
    n, k = LI()
    a = S()
    ans = 0
    for i in range(n - 1):
        if a[i] == a[i + 1]:
            ans += 1
    print((min(n - 1, ans + 2 * k)))
    return


# E
def E():
    def add(i):
        while i <= n:
            bit[i] += 1
            i += i & -i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i & -i
        return res

    n = I()
    p = LI()
    r = [0] * n
    bit = [0] * (n + 1)
    for i in range(n)[::-1]:
        r[i] = (n - i - 1) - sum(p[i])
        add(p[i])
    print(r)
    l = [0] * n
    bit = [0] * (n + 1)
    for i in range(n):
        l[i] = i - sum(p[i])
        add(p[i])
    print(l)
    return


# F
def F():
    n = I()
    s = LI()
    s.sort()
    s = s[::-1]
    if s[0] == s[1]:
        print("No")
        return
    a = [s[0]]
    j = 1
    s.append(0)
    q = deque()
    for _ in range(n):
        for i in range(1 << _):
            if a[i] > s[j]:
                a.append(s[j])
                j += 1
            else:
                q.append(a[i])
    print(a)
    return


# Solve
if __name__ == "__main__":
    D()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    s = eval(input())
    ans = 0
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            ans += 1
    print((min(ans + 2 * k, n - 1)))
    return


# Solve
if __name__ == "__main__":
    solve()

+from itertools import permutations -# A -def A(): -    n = I() -    print((n**3)) -    return -# B -def B(): -    n = I() -    a = LI() -    b = LI() -    c = LI() -    ans = sum(b) -    for i in range(n - 1): -        x = a[i] -        y = a[i + 1] -        if y == x + 1: -            ans += c[x - 1] -    print(ans) -    return - - -# C -def C(): -    n = I() -    b = LI() -    b.append(float("inf")) -    a = [min(b[i], b[i - 1]) for i in range(n)] -    print((sum(a))) -    return - - -# D -def D(): +def solve(): -    a = S() +    s = eval(input()) -        if a[i] == a[i + 1]: +        if s[i] == s[i + 1]: -    print((min(n - 1, ans + 2 * k))) -    return - - -# E -def E(): -    def add(i): -        while i <= n: -            bit[i] += 1 -            i += i & -i - -    def sum(i): -        res = 0 -        while i > 0: -            res += bit[i] -            i -= i & -i -        return res - -    n = I() -    p = LI() -    r = [0] * n -    bit = [0] * (n + 1) -    for i in range(n)[::-1]: -        r[i] = (n - i - 1) - sum(p[i]) -        add(p[i]) -    print(r) -    l = [0] * n -    bit = [0] * (n + 1) -    for i in range(n): -        l[i] = i - sum(p[i]) -        add(p[i]) -    print(l) -    return - - -# F -def F(): -    n = I() -    s = LI() -    s.sort() -    s = s[::-1] -    if s[0] == s[1]: -        print("No") -        return -    a = [s[0]] -    j = 1 -    s.append(0) -    q = deque() -    for _ in range(n): -        for i in range(1 << _): -            if a[i] > s[j]: -                a.append(s[j]) -                j += 1 -            else: -                q.append(a[i]) -    print(a) +    print((min(ans + 2 * k, n - 1))) -    D() +    solve()