Use this:
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$5000)/(($A$2:$A$5000=$E$1)*(ISNA(MATCH($B$2:$B$5000,G$1:G1,0)))),1)),"")

If it can contain numbers as well... there was a problem. Your original example had text that looked like numbers. The best fix is to select column A. Data/Text to numbers/Finish.

Then the formula above will work perfectly for words, or numbers, or both.