#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(){
	int i,count[1001][2];
	bool f = false;
	string a,b;
	for(i = 0;i < 1001;++i){
		for(int j = 0;j < 2;++j){
			count[i][j] = 0;
		}
	}
	while(cin >> a){
		b = "\0";
		if(a.size() == 0) f = true;
		for(i = 0;a[i] != ',';++i){
			b += a[i];
		}
		if(f) ++count[atoi(b.c_str())][1];
		else ++count[atoi(b.c_str())][0];
	}
	for(i = 1;i < 1001;++i){
		if(count[i][0] > 0 && count[i][1] > 0){
			cout << i << endl;
		}
	}
	return 0;
}