#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<pair<int,int> >V;
    int a,b;
    while(scanf("%d,%d",&a,&b),a&&b){
        V.push_back(make_pair(b,a));
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    int n;
    while(cin>>n){
        int R=0,buf=10000000;
        for(int i=0;;i++){
            if(V[i].first<buf){
                R++;
                buf=V[i].first;
            }
            if(V[i].second==n)break;
        }
        cout<<R<<endl;
    }

}