1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <vector>

using namespace std;

int main() {
	std::ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<bool> found_brands(n, false);
	int moves = 0;
	int all_moves = 0;
	while (k > 0 && n > 0) {
		int bottle;
		cin >> bottle;
		bottle--; n--;
		if (!found_brands[bottle]) {
			k--;
			found_brands[bottle] = true;
			all_moves += moves;
		} else {
			moves++;
		}
	}
	cout << (k == 0 ? all_moves : -1) << endl;
	return 0;
}