using System;
class Program
{ 
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        int n = int.Parse(s[0]), m = int.Parse(s[1]);
        (int a, int b)[] x = new (int, int)[n];
        (int c, int d)[] y = new (int, int)[m];
        for (int i = 0; i < n; i++)
        {
            s = Console.ReadLine().Split();
            x[i].a = int.Parse(s[0]);
            x[i].b = int.Parse(s[1]);
        }
        for (int i = 0; i < m; i++)
        {
            s = Console.ReadLine().Split();
            y[i].c = int.Parse(s[0]);
            y[i].d = int.Parse(s[1]);
        }
        Console.WriteLine("{0}\n1\n{0}", Math.Min(x[0].b, y[0].d));
    }
}