package sep2th.pinduoduo;
import java.util.*;
* @Author ZhangQiong nwsuafzq@hotmail.com
* @Date 2017/9/2
* @Time 14:56.
*/
public class Main {
public static void func(int m,ArrayList<Integer> candylist, LinkedHashMap<Integer,Integer> bearmap){
Object[] key_arr = bearmap.keySet().toArray();
Arrays.sort(key_arr);
for (int i=key_arr.length-1;i>=0;i--) {
int value = bearmap.get(key_arr[i]);
int shengyu=value;
int index=0;
for (int j = index; j <candylist.size(); j++) {
if(shengyu-candylist.get(j)>=0) {
shengyu = shengyu - candylist.get(j);
candylist.remove(j);
j--;
}
bearmap.put((Integer) key_arr[i],shengyu);
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> candylist=new ArrayList();
LinkedHashMap<Integer,Integer> bearmap=new LinkedHashMap<Integer,Integer>();
int n=scanner.nextInt();
int m=scanner.nextInt();
for (int i = 0; i <m ; i++) {
candylist.add(scanner.nextInt());
}
Collections.sort(candylist);
Collections.reverse(candylist);
) {
System.out.println(i);
}*/
for (int i = 0; i <n ; i++) {
int k=scanner.nextInt();
int v=scanner.nextInt();
bearmap.put(k,v);
}
func(m,candylist,bearmap);
Set<Integer> keySet = bearmap.keySet();
Iterator<Integer> iter = keySet.iterator();
while(iter.hasNext()){
int key = iter.next();
System.out.println(bearmap.get(key));
}
}
}