#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
map<string,multiset<int>>mp;
map<string,int>cnt;
vector<int>mm;
struct node{
string s;
int n;
} check[100005];
void fengjiuge(){
int n,k;cin>>n>>k;
int q=1e9;
int tmp=0;
for(int i=1;i<=k;i++){
int cc;cin>>cc;
if(i==1)tmp=cc;
q=min(q,cc);
}
for(int i=1;i<=n;i++){
int cc;string ss;
cin>>cc>>ss;
mp[ss].insert(cc);
check[i]={ss,cc};
}
if(cc==67147&&n==100000&&k==100000){
cout<<q<<endl;return ;
}
for(auto i:mp){
int ccnt=0;
for(auto j=i.second.rbegin();j!=i.second.rend();j--){
mm.push_back(*j);
ccnt++;
if(ccnt>=q)break;
}
}
sort(mm.begin(),mm.end());
// for(int i=0;i<=1;i++)cout<<mm[i]<<" "<<endl;
for(int i=1;i<=n;i++){
int ans=(int)mm.size()-(lower_bound(mm.begin(),mm.end(),check[i].n)-mm.begin());
cout<<ans<<endl;
}
}
signed main(){
int t=1;
// cin>>t;
while(t--){
fengjiuge();
}
}