#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
const int N = 1000005;

int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if (m == 1) {
		cout << "0\n"; return 0;
	}
	for (int i = 1; i <= n; ++i) {
		cin >> a[i], cnt[a[i]]++, p[a[i]].push_back(i);
	}
	set<ii> s;
	for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
	for (int i = 1; i <= m; ++i) {
		res[i] = 1e9;
		for (int j = 0; j < 2; ++j) {
			vector<int> go;
			int sum = 0;
			for (int k = 0; k < p[i].size(); ++k) {
				if (p[i][k] % 2 == j) {
					int cur = a[p[i][k] - 1];
					if (p[i][k] > 1 && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
				else {
					int cur = a[p[i][k] + 1];
					if (p[i][k] < n && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
			}
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]], go[k])));
				s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
			}
			s.erase(s.find(ii(cnt[i], i)));
			res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
				s.insert(ii(cnt[go[k]], go[k]));				
			}
			s.insert(ii(cnt[i], i));
			for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
		}
		cout << res[i] << '\n';
	}
}