#include <bits/stdc++.h>
using namespace std;

#define ll long long


int main()
{

    int n, m;
    cin >> n >> m;
    vector<int> a(n),b(n),c(m),d(m);
    map<int, int> d1;
    map<int, int> b1;
    bool ind = true;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    
        b1[b[i]] = i; 
    }
    int maks = 0;
    for(int j = 0; j < m; j++)
    {
        cin >> c[j] >> d[j];
        maks = max(maks, d[j]);
        d1[d[j]] = j;
    }
    
    
    if(n == 0)
    {
        int x = 1;
        int y = 0;
        int val;
        if(b[0] <= maks)
        {
            int dif = b[0] - d[0];
            for(int j = 0; j < m; j++)
            {
                if(b[0] - d[j] < dif)
                {
                    dif = b[0] - d[j];
                    y = j + 1;
                    val = d[j];
                }
            }
        }
        else
        {
            int val = 0;
            for(int j = 0; j < m; j++)
            {
                val = max(val, d[j]);
                y = j + 1;
            }
        }
    }
    
    
    
    cout << k << endl;
    cout << 1 << endl;
    cout << 1 << y << val << endl;
   /* int minIncrease = 1;
    for(int i = 0; i < n; i++)
    {
        auto it = lower_bound(d.begin(), d.end(), b[i]);
        stampaj[i][0] = i + 1;
        if(it == d.end())
        {
            if(*(it - 1) > b[i])
            {
                stampaj[i][1] = d1[*(it - 1)];
                stampaj[i][2] = *(it - 1);
            }
            else
            {
                stampaj[i][1] = d1[d[0 + minIncrease]];
                stampaj[i][2] = d[0 + minIncrease];
                minIncrease++;
            }
        }

        else if(*it == b[i])
        {
            stampaj[i][1] = d1[*it] + 1;
            stampaj[i][2] = b[i];
        }
        else
        {
            stampaj[i][1] = d1[*it] + 1;
            stampaj[i][2] = b[i];
        }
        /*
        if(*it != b[i])
        {
            stampaj[i][1] = d1[*(it - 1)] + 1;
        }
        else
        {
            stampaj[i][1] = d1[*it] + 1;
            stampaj[i][2] = *it;
            k += *it;
        }

        else
        {
            stampaj[i][2] = *it;
            k += *it;
        }*/
      //  k += stampaj[i][2];
    //}

    
    
    
    
    
    
    
    
    
    

    return 0;
}