public class Main {
public static int m = 0, n = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextLine().split(" ").length;
int b = sc.nextLine().split(" ").length;
n = a + b;
m = a + b;
int edges = Integer.valueOf(sc.nextLine());
int[][] map = new int[n+1][m+1];
for (int i = 0; i < edges; i++) {
String[] line = sc.nextLine().split(" ");
map[Integer.valueOf(line[0])][Integer.valueOf(line[1])] = 1;
}
System.out.println(getMaxMun(map));
}
private static int getMaxMun(int[][] map) {
int count = 0;
int[] linked = new int[m];
for (int i = 0; i < m; i++) {
linked[i] = -1;
}
for (int i = 0; i < n; i++) {
boolean[] used = new boolean[m];
if (dfs(map, used, linked, i))
count++;
}
return count;
}
private static boolean dfs(int[][] map, boolean[] used, int[] linded, int start) {
for (int i = 0; i < m; i++) {
if (used[i] == false && map[start][i] == 1) {
used[i] = true;
if (linded[i] == -1 || dfs(map, used, linded, linded[i])) {
linded[i] = start;
return true;
}
}
}
return false;
}
}
#网易笔试##笔试题目##面经#