#include <stdio.h>
#include <string.h>

int main(void) {
	int i,j,n,req,tmp;
	int c[101],p[101],rank[100];
	
	i = 0;
	while(1){
		scanf("%d,%d",&c[i],&p[i]);
		if(!(c[i]*p[i])) break;
		i++;
	}
	n = i;
	
	memset(rank,0,sizeof(rank));
	
	for(i = 0;i < n-1;i++){
		for(j = i;j < n;j++){
			if(p[i] < p[j]){
				p[i] ^= p[j] ^= p[i] ^= p[j];
				c[i] ^= c[j] ^= c[i] ^= c[j];
			}
		}
	}
	
	rank[0] = 1;
	tmp = 0;
	for(i = 1;i < n;i++){
		if(p[tmp] == p[i]){
			rank[i] = rank[tmp];
		}else{
			rank[i] = rank[tmp]+1;
			tmp = i;
		}
	}
	
	while(scanf("%d",&req) != EOF){
		for(i = 0;i < n;i++){
			if(c[i] == req){
				printf("%d\n",rank[i]);
			}
		}
	}
	
	return 0;
}