#include<iostream>

using namespace std;

int main(){
	int team[101];
	int score[101];
	int rank[101]={0};
	int c=0;
	int n;
	char x;
	
	while(cin>>team[c]>>x>>score[c],score[c]!=0)c++;
	//cout<<rank[0]<<endl<<rank[1]<<endl;
	for(int i=0;i<=c;i++){
		for(int j=0;j<=c;j++){
			if(score[i]<score[j]){rank[i]++;}
		}
		//cout<<++rank[i]<<endl;
		rank[i]++;
	}
	
	while(cin>>n){

	cout<<rank[n-1]<<endl;
	
	}
}