#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    int number,score;
    int rank[101]={0};
    int team[101]={0};
    while(scanf("%d,%d",&number,&score),number||score){
        team[number]=score;
    }
    int log=1;
    for(int i=0; i<100; i++){
        int max=0;
        int count=0;
        for(int j=1; j<101; j++){
            if(rank[j]!=0)
                continue;
            if(team[j]>max){
                max=team[j];
            }
        }
        for(int j=1; j<101; j++){
            if(team[j]==max){
                rank[j]=log;
                count++;
            }
        }
        log += count;
    }
    log=1;
    for(int i=1; i<101; i++){
        if(team[i]>0){
            log++;
        }
    }
    for(int i=1; i<101; i++){
        if(team[i]==0){
            rank[i]=log;
        }
    }
    int n;
    while(cin>>n,!cin.eof()){
        cout<<rank[n]<<endl;
    }
    return 0;
}