#include <algorithm>
#include <string>
#include <unordered_map>
#include <iostream>
#include <vector>
using namespace std;
struct Team {
int strength;
string uni;
int rank;
int id;
};
int main() {
int n, k;
cin >> n >> k;
vector<int> c(k);
for (int i = 0; i < k; ++i) {
cin >> c[i];
}
vector<Team> teams(n);
for (int i = 0; i < n; ++i) {
cin >> teams[i].strength >> teams[i].uni;
teams[i].id = i;
teams[i].rank = -1; // 初始化排名
}
// 根据队伍的实力排序,实力高的在前
sort(teams.begin(), teams.end(), [](const Team &a, const Team &b) {
return a.strength > b.strength;
});
for (int i = 0; i < n; ++i) {
int bestRank = INT_MAX;
for (int j = 0; j < k; ++j) {
int currentRank = 0;
unordered_map<string, int> uniCount;
for (int m = 0; m < i; ++m) {
if (teams[m].rank == j) {
uniCount[teams[m].uni]++;
}
}
if (uniCount[teams[i].uni] < c[j]) {
currentRank += 1; // 队伍i可以被分配到竞赛j
for (int m = i + 1; m < n; ++m) {
if (teams[m].strength > teams[i].strength) {
currentRank += 1;
}
}
bestRank = min(bestRank, currentRank);
}
}
teams[i].rank = bestRank;
}
// 输出每个队伍的最坏情况下的最小排名
for (const auto &team : teams) {
cout << team.rank << endl;
}
return 0;
}