#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

using namespace std;

int main()
{
	vector<int> value,result;
	int a,b;
	char c;

	while(cin >> a >> c >> b && a && b)
	{
		value.pb(b);
		result.pb(b);
	}

	sort(result.begin(),result.end());
	result.erase(unique(result.begin(),result.end()),result.end());
	sort(result.begin(),result.end(),greater<int>());

	int team;
	while(cin >> team)
	{
		rep(i,result.size())
		{
			if(value[team-1] ==  result[i])
			{
				cout << i+1 << endl;
			}
		}
	}

	return 0;
}