using System;
using System.ComponentModel.Design;
class Program
{
    static void rastavi(ref long a,ref int b,string s)
    {
        string[] ras=s.Split(' ');
        a = long.Parse(ras[0]);
        b = int.Parse(ras[1]);
    }
    static long pojela(long[] d, int[] p, long q,int n)
    {
        int o = 0;
        int dan = 1;   
        long pojela = 0;
        long keks = 0;
        for (int i = 0; i < n; i++)
        {
            keks += p[i];
          //  Console.WriteLine(p[i]);
        }
        //Console.WriteLine(keks + " ovo je koliko ima keksa");
        //int i = 0; 
        if (keks < q)
        {
            pojela = keks;

        }
        else
        {
            while (dan <= q)
            {
                for (int i = 0; i < n; i++)
                {
                    if (dan == d[i])
                    {
                        o += p[i];
                    }
                }
                if (o > 0)
                {
                    o--;
                    pojela++;

                }
                dan++;
            }
        }
        return pojela;
    }
    static void Main()
    {
        string nq=Console.ReadLine();
        string[] qn = nq.Split(' ');
        int n = int.Parse(qn[0]);
        int q = int.Parse(qn[1]);
        long[] d=new long[n];
        int[] p=new int[n];
        for (int i = 0; i < n; i++)
        {
            string s = Console.ReadLine();
            rastavi(ref d[i], ref p[i], s);
        }
        long[] pit=new long[q];
        long[] m = new long[q];
        for (int i = 0; i < q; i++)
        {
            pit[i] = long.Parse(Console.ReadLine());
            m[i]=pojela(d, p, pit[i], n);
        }
        for (int i = 0; i < q; i++)
        {
            Console.WriteLine(m[i]);
        }
    }
}