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

int main(){
	int count[1001][2],c,n;
	string a,b;
	for(int i = 0;i < 1001;++i){
		for(int j = 0;j < 2;++j){
			count[i][j] = 0;
		}
	}
	while(getline(cin,a)){
		if(a == "\n") break;
		c = 0;
		b[c] = a[c];
		n = a.find(',');
		for(;c < n;++c){
			b += a[c];
		}
		++count[atoi(b.c_str())][0];
	}
	while(getline(cin,a)){
		if(a == "\n") break;
		c = 0;
		b[c] = a[c];
		n = a.find(',');
		for(;c < n;++c){
			b += a[c];
		}
		++count[atoi(b.c_str())][1];
	}
	for(int i = 1;i < 1001;++i){
		if(count[i][0] > 0 && count[i][1] > 0){
			cout << i << endl;
		}
	}
	return 0;
}