/*
 * Created by SharpDevelop.
 * User: Home
 * Date: 11/16/2024
 * Time: 12:19 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

namespace Plazma
{
	class Program
	{
		static uint pitanje(Dictionary<ulong, ulong> liste, ulong k)
		{
			uint br = 0;
			ulong preostalo_plazme = 0;
			for(ulong i=0; i<=k; i++)
			{
				if(liste.ContainsKey(i))
				{
					preostalo_plazme += liste[i];
				}
				
				if(preostalo_plazme > 0)
				{
					br++;
					preostalo_plazme--;
				}
			}
			
			return br;
		}
		public static void Main(string[] args)
		{
			Console.Write("Unesite N i Q redom (razdvojite razmakom): ");
			string[] niz = Console.ReadLine().Split();
			
			int N = int.Parse(niz[0]);
			int Q = int.Parse(niz[1]);
			
			Console.WriteLine("U narednih " + N + " redova unesite d i p redom (razdvojite razmakom): ");
			
			var liste = new Dictionary<ulong, ulong>();
			
			for(int i=0; i<N; i++)
			{
				string[] niz1 = Console.ReadLine().Split();
				liste.Add(ulong.Parse(niz1[0]), ulong.Parse(niz1[1]));
			}
			
			ulong suma = 0, kljucevi = 0;
			foreach(ulong m in liste.Keys)
			{
				suma += liste[m];
				kljucevi += m;
			}
			
			Console.WriteLine("U narednih " + Q + " redova unesite broj k: ");
			
			var lista_k = new List<ulong>();
			for(int j=0; j<Q; j++)
			{
				string k = Console.ReadLine();
				lista_k.Add(ulong.Parse(k));
			}
			
			for(int j=0; j<lista_k.Count; j++)
			{
				if(lista_k[j] >= suma)
				{
					Console.WriteLine(suma);
				}
				else
				{
					uint pojedeno = pitanje(liste, lista_k[j]);
					Console.WriteLine(pojedeno);
				}
			}
			
			// TODO: Implement Functionality Here
			
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}