#include <cstdio>
#include <algorithm>

using namespace std;

int a[300000];

int main() {
    int n, k, c, i, j;
    long long ans = 0;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    sort(a, a + n);
    
    c = k;
    
    for (i = 0, j = 0; ; i++) {
        int x = 0;
        
        while (j < n && a[j] == i) {
            x++;
            j++;
        }
        
        if (x < c) {
            ans += (long long)i * (c - x);
            
            c = x;
        }
        
        if (c == 0) break;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

class UnionFind {
public:
	UnionFind(int n) : par(n), rank(n, 0) {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
		}
	}

	int root(int x) {
		return par[x] == x ? x : par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}
	
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) {
				++rank[x];
			}
		}
	}
private:
	vector<int> par, rank;
};

const int MAX = 200001;

int main() {
	int n;
	cin >> n;

	vector<int> v(n);
	for (auto& nx : v) {
		cin >> nx;
	}

	UnionFind uf(MAX);
	for (int i = 0; i < n / 2; ++i) {
		uf.unite(v[i], v[n - 1 - i]);
	}

	int ans = 0;
	for (int j = 0; j < MAX; ++j) {
		if (uf.root(j) != j) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}