#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

pair<int, int> next_time() {
	int sh, sm, eh, em;
	scanf("%d:%d-%d:%d", &sh, &sm, &eh, &em);
	return make_pair(sh * 60 + sm, eh * 60 + em);
}

vector<pair<int, int>> input_schedule() {
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> res(n);
	for(auto &e : res) e = next_time();
	return res;
}

bool contain(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first <= b.first && b.second <= a.second;
}

int main() {
	const auto classes = input_schedule();

	int n;
	scanf("%d", &n);
	vector<vector<pair<int, int>>> students(n);
	for(auto &e : students) e = input_schedule();

	int m;
	scanf("%d", &m);
	vector<vector<pair<int, int>>> teachers(m);
	for(auto &e : teachers) e = input_schedule();

	int res = 0;
	for(const auto &c : classes) {
		int cnt = 0;
		for(const auto &s : students) {
			for(const auto &e : s) {
				if(contain(e, c)) {
					++cnt;
				}
			}
		}

		for(const auto &t : teachers) {
			for(const auto &e : t) {
				if(cnt && contain(e, c)) {
					++res;
					--cnt;
				}
			}
		}
	}

	printf("%d\n", res);

	return EXIT_SUCCESS;
}