using System;

namespace MyApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);
            int[] Ai = new int[N];
            int[] Bi = new int[N];
            int[] Cj = new int[M];
            int[] Dj = new int[M];
            for (int i = 0; i < N; i++)
            {
                string[] sN = Console.ReadLine().Split();
                Ai[i] = int.Parse(sN[0]); Bi[i] = int.Parse(sN[1]);
            }
            for (int j = 0; j < M; j++)
            {
                string[] sM = Console.ReadLine().Split();
                Cj[j] = int.Parse(sM[0]); Dj[j] = int.Parse(sM[1]);
            }
            int[] arr = new int[M];
            int suma = 0;
            for (int i = 0; i < M; i++)
            {
                arr[i] = Cj[i];
                suma += arr[i];
            }
            Console.WriteLine(suma + " " + Bi[0]);
            if (suma < Bi[0])
            { 
                for (int i = 0; i < M; i++)
                 {
                    if (arr[i] < Dj[i] && suma + Dj[i] - arr[i] <= Bi[0])
                    {
                        suma += -arr[i]+Dj[i];
                        arr[i] = Dj[i];
                        

                    }
                    else if (suma < Bi[0] && arr[i] < Dj[i])
                    {
                        arr[i] += Bi[0]-suma;
                        suma += arr[i];
                    }
                 }
            }
            for(int i = 0; i < M; i++) { Console.Write(arr[i] + " "); }
          

        }
    }
}