#include <iostream>

#define MAX_N 50000
#define MAX_M 50000

int a[MAX_N];
int b[MAX_N];
int c[MAX_M];
int d[MAX_M];
int main()
{
	int n, m;

	std::cin >> n >> m;

	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i] >> b[i];
	}
	for (int j = 0; j < m; ++j)
	{
		std::cin >> c[j] >> d[j];
	}
		
	std::cout << std::max(std::max(std::initializer_list<int>(d, d + m)), b[0]);

	return 0;
}