import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var query = false
  var s = ""
  var a = new ArrayBuffer[(Int,Int)]
  while( { s = readLine.trim;s } != "0,0" ) {
    val n = s.split(",").map(_.toInt)
    a += ((n(1),n(0)))
  }
  val g = a.groupBy(n=>n._1).mapValues(_.map(_._2)).toSeq.sortWith(_._1 > _._1)
  try {
    while(true) {
      val n = readInt
      println(g.indexWhere(i => i._2.exists( i => i==n ))+1)
    }
  } catch { case e:Exception => Nil }
}