
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
int n = Integer.parseInt(inputs[0]);
int m = Integer.parseInt(inputs[1]);
HashSet<String> set = new HashSet<>();
for(int i=0; i<n; i++) {
set.add(br.readLine());
}
ArrayList<String> result = new ArrayList<>();
for(int i=0; i<m; i++) {
String str = br.readLine();
if(set.contains(str)) {
result.add(str);
}
}
Collections.sort(result);
System.out.println(result.size());
for(String s:result) {
System.out.println(s);
}
}
}