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 $\frac{n}{k}$ 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.


-----Input-----

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_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 2), a_{i} is the i-th element of the array.


-----Output-----

Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print 0.


-----Examples-----
Input
6 2
2 1 2 2 2 1

Output
1

Input
8 4
1 1 2 1 1 1 2 1

Output
0

Input
9 3
2 1 1 1 2 1 1 1 2

Output
3



-----Note-----

In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].

In the second sample, the given array already is 4-periodic.

In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic.

Difficulty: interview

Starter code:

Solutions:
n, k = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(k):
    c1 = c2 = 0
    for j in range(i, n, k):
        if A[j] == 1:
            c1 += 1
        else:
            c2 += 1
    ans += min(c1, c2)
print(ans)

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
poc = 0
for i in range(k):
	p1,p2 = 0,0
	for j in range(i,n,k):
		if a[j] == 1:
			p1+=1
		else:
			p2+=1
	poc+=min(p1,p2)
print(poc)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
c = []
for i in range(k):
    c.append([0, 0])
#~ print(c)
for i in range(k):
    b.append(a[i])
par = True
ans = 0
for i in range(n):
    if (a[i] != b[i % k]):
        par = False
    c[i % k][a[i] - 1] += 1
if (par):
    print(0)
else:
    for i in range(k):
        ans += min(c[i])
    print(ans)
    


from math import *

[n, k] = [int(i) for i in input().split()]
arr = [int(i) - 1 for i in input().split()]
arr2 = [[0 for i in range(2)] for j in range(k)]
r = 0
for i in range(n // k):
    for j in range(k):
        arr2[j][arr[i * k + j]] += 1
for j in range(k):
    r += min(arr2[j][0], arr2[j][1])
print(r)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(k):
    t1, t2 = 0, 0
    for j in range(i, n, k):
        if a[j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print(ans)


n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
ans=0
for i in range(k):
    ones=0
    twos=0
    for j in range(n//k):
        num=l[i+j*k]
        if(num==1):
            ones+=1
        else:
            twos+=1
    ans+=min(ones,twos)
print(ans)


n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
for i in range(k):
    c = [0] *2
    for j in range(i,n,k):
        c[a[j]-1]+=1
    ans+=min(c)
print(ans)


n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(k):
    s1, s2 = 0, 0
    for j in range(i, n, k):
        if A[j] == 1:
            s1+=1
        else:
             s2+=1
    ans = ans + min(s1, s2)
print(ans)

inputs = [int(string) for string in input().split()]
n = inputs[0]
k = inputs[1]
count = int(n / k)
array = [int(string) for string in input().split()]
summ = int(0)
various = []

for i in range(int(0), int(k)):
    various.append(0)

for i in range(len(array)):
    if (array[i] == 1) :
        various[i % k] += 1
    else :
        various[i % k] -= 1

for i in range(int(0), int(k)):
    summ += (count - abs(various[i])) / 2

print(int(summ))

3

def readln(): return tuple(map(int, input().split()))

n, k = readln()
a = readln()
ans = 0
for i in range(k):
    cnt = len([1 for j in range(i, n, k) if a[j] == 1])
    ans += min(cnt, n // k - cnt)
print(ans)


print ((lambda n: (lambda data, k: sum(min (data[i::k].count(1), data[i::k].count(2)) for i in range (k)))(list(map(int, input().split())), int(n[1])))(input().split()))

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

L=list(map(int,input().split()))

A=[]
for i in range(0,n,k):
    A.append(list(L[i:i+k]))
z=n//k
ans=0
for i in range(k):
    one=0
    two=0
    for j in range(z):
        if(A[j][i]==1):
            one+=1
        else:
            two+=1
    ans+=min(one,two)
print(ans)


n, k = map(int, input().split())
s, d = 0, n // k
t = input()[:: 2]
for i in range(k):
    p = t[i :: k].count('1')
    s += min(d - p, p)
print(s)

read = lambda:list(map(int, input().split()))
n,k = read()
m = n//k
a = list(read())
result = 0
for i in range(k):
    t = a[i:n:k]
    s = t.count(1)
    result += min(s, m-s)
print(result)


n,k=tuple(map(int,input().split()))
a=list(map(int,input().split()))
print(sum((lambda x:min(x-n//k,2*n//k-x))(sum(a[i::k])) for i in range(k)))


from collections import Counter
n,k = list(map(int, input().split()))
ar = list(map(int, input().split()))
kc = []
ris = 0
for cont in range(0,n-k+1,k):
    kc.append(ar[cont:cont+k])
for cont in range(0,k):
    l = []
    for cont2 in range(0,len(kc)):
        l.append(kc[cont2][cont])            
        a = Counter(l).most_common(1)[0][1]
    ris += len(kc)-a
print(ris)


# -*- coding: utf-8 -*-

n, k = map(int, input().split())
a = list(map(int, input().split()))

m = 0
for i in range(k):
    s = a[i::k]
    c = [s.count(x) for x in set(s)]
    m += len(s) - max(c)
print(m)

R = lambda: map(int, input().split())
n, k = R()
a = list(R())
print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))



import sys
import math
  
n, k = [int(x) for x in (sys.stdin.readline()).split()]
an = [int(x) for x in (sys.stdin.readline()).split()]

res = 0
for i in range(k):
    k1 = 0
    k2 = 0
    for j in range(i, n, k):
        if(an[j] == 1):
            k1 += 1
        else:
            k2 += 1       
    res += int(n / k) - max(k2, k1)
    
print(res)

n, k = map(int, input().split())
a, val = list(map(int, input().split())), 0
for i in range(k):
    c = sum(a[i + j * k] == 1 for j in range(n // k))
    val += min(c, n // k - c)
print(val)

n, k = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
l = [0] * k
for i in range(k):
	l[i] = v[i::k].count(1)
ans = 0
n //= k
for x in l:
	ans += min(x, n - x)
print(ans)


def main():
    n, k = map(int, input().split())
    l = input().split()
    print(sum(min(nn.count('1'), nn.count('2')) for nn in zip(*[l[i:i + k] for i in range(0, n, k)])))


def __starting_point():
    main()
__starting_point()

def main():
    n, k = list(map(int, input().split()))
    arr = list(map(int, input().split()))
    got = [0]*(k+1)

    for i in range(0, k):
        for j in range(n//k):
            if arr[j*k+i]==1:
                got[i] += 1
    answer = 0

    for i in range(k):
        answer += min(got[i], n//k-got[i])

    print(answer)

main()