import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Array
import Control.Monad

main = do
  li <- BS.getLine
  let [n,q] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  bas <- forM [2..n] getba
  pxs <- forM [1..q] getpx
  let ans = compute n q bas pxs
  putStrLn $ unwords $ map show ans

getba _ = do
  li <- BS.getLine
  let [a,b] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  return (b,a)

getpx _ = do
  li <- BS.getLine
  let [p,x] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  return (p,x)

compute :: Int -> Int -> [(Int,Int)] -> [(Int,Int)] -> [Int]
compute n _ bas pxs = elems sa
  where
    xa = accumArray (+) 0 (1,n) pxs
    xs = elems xa
    sa = listArray (1,n) ( head xs : [ x + sa ! i | (x,(_,i)) <- zip (tail xs) (sort bas) ])
