This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.

Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8f8616e518b67af73332593c4c73ae9f207dc04.png" style="max-width: 100.0%;max-height: 100.0%;"/> times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*.

For example, any array is *n*-periodic, where *n* is the array length. Array [2, 1, 2, 1, 2, 1] is at the same time 2-periodic and 6-periodic and array [1, 2, 1, 1, 2, 1, 1, 2, 1] is at the same time 3-periodic and 9-periodic.

For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0.
The first line of the input contains a pair of integers *n*, *k* (1 ≤ *k* ≤ *n* ≤ 100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 2), *a*<sub class="lower-index">*i*</sub> is the *i*-th element of the array.
import copy

def process_patterns(k, arn):
    all_ = []
    current = []
    k_ = 0
    for i in arn:
        current.append(i)
        k_+=1
        if k_ == k:
            all_.append(current)
            current = []
            k_ = 0

    return all_

def make_patterns(patterns):
    pat = []
    pat2 = []
    for p in patterns:
        if p not in pat:
            pat.append(p)
            pat2.append([p, 1])
        else:
            for p2 in pat2:
                if p2[0] == p:
                    p2[1] += 1
            
    return pat, pat2

# turns dest into src
def into(dest, src):

    moves = 0
    for i in range(0, len(src)):
        if dest[i] != src[i]:
            moves += 1

    return moves

def monotonized_patterns(k):
    m = []
    for p in [1, 2]:
        pat = []
        for i in range(k):
            pat.append(p)
        m.append(pat)
    return m

def cheapest_pattern(patterns, k):
    only_patterns, count = make_patterns(patterns)
    score = []
    for p in only_patterns:
        sc = 0
        for p2 in only_patterns:
            if p2 == p:
                continue
            sc1 = into(p2, p)
            count_ = 0
            for i in count:
                if i[0] == p2:
                    count_ = i[1]
                    break
            sc1 *= count_
            sc += sc1
        score.append(sc)

    for p in monotonized_patterns(k):
        if p not in only_patterns:
            sc = 0
            for p2 in only_patterns:
                sc1 = into(p2, p)
                count_ = 0
                for i in count:
                    if i[0] == p2:
                        count_ = i[1]
                        break
                sc1 *= count_
                sc += sc1
            score.append(sc)
            
    return min(score)

def main():
    n, k = map(lambda x: int(x),input().split())
    arn = map(lambda x: int(x),input().split())

    solution = cheapest_pattern(process_patterns(k, arn), k)
    print(solution)

main()
    

