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

class Team {
public:
    int id_;
    int solve_;
    int rank_;

    Team(int id, int solve) {
        id_ = id;
        solve_ = solve;
    }
};

bool moreSolve(const Team &t1, const Team &t2) {
    return t1.solve_ > t2.solve_;
}

bool lessId(const Team &t1, const Team &t2) {
    return t1.id_ < t2.id_;
}

int main () {
    vector<Team> teams;
    int id, solve;
    while (scanf("%d,%d", &id, &solve), id && solve) {
        teams.push_back(Team(id, solve));
    }

    sort(teams.begin(), teams.end(), moreSolve);
    teams[0].rank_ = 1;
    solve = teams[0].solve_;
    for (int i = 1, size = teams.size(); i < size; i++) {
        if (teams[i].solve_ == solve) {
            teams[i].rank_ = teams[i - 1].rank_;
        } else {
            teams[i].rank_ = teams[i - 1].rank_ + 1;
            solve = teams[i].solve_;
        }
    }

    sort(teams.begin(), teams.end(), lessId);
    while (cin >> id) {
        for (vector<Team>::iterator it = teams.begin(); it != teams.end(); it++) {
            if (it->id_ == id) {
                cout << it->rank_ << endl;
            }
        }
    }
}