#include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;
int main (void){

  int  a ,b[MAX] , jun[MAX] , temp[MAX] , b2[MAX];
  char c;
  int stop = 0;
  int j = 1 ;
  
  while (1){




    cin >> a   >> c >> b[a];

    b2[a] = b[a];
    

    if ( a == 0 && b[a] == 0) break;

    

    stop++;

    }

  
  

  sort( b , b + stop  );
  
  
  for (int i = 1 ; i < stop ; i++){


    temp[i] = b[stop - i ]; 



  }

  for(int i = 1 ; i < stop ; i++){

  
    b[i] = temp[i];


  

  }


  for(int i = 1; i < stop  ; i++){

 
   

    if( b[i] != b[i + 1]  ) jun[ b[i] ] = j++;
    else  continue;

   

  }




  

  while ( cin >> j){


    cout << jun[b2[j]] <<endl  ;



  }
  


  return 0;
}