import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();// 小熊数量
int m = sc.nextInt();// 糖数量
ArrayList<Integer> al = new ArrayList<Integer>();// 存储糖的能量
LinkedHashMap<Integer, Integer> lm = new LinkedHashMap<Integer, Integer>();
int b_fight[] = new int[n];// 战斗力
for (int i = 0; i < m; i++) {
al.add(sc.nextInt());
}
for (int i = 0; i < n; i++) {
b_fight[i] = sc.nextInt();
lm.put(b_fight[i], sc.nextInt());
}
Arrays.sort(b_fight);
Collections.sort(al);
for (int i = n - 1; i >= 0; i--) {
for (int j = al.size() - 1; j >= 0; j--) {
if (lm.get(b_fight[i]) - al.get(j) >= 0) {
lm.put(b_fight[i], lm.get(b_fight[i]) - al.get(j));
al.remove(j);
}
}
}
Set<Map.Entry<Integer, Integer>> entrySet = lm.entrySet();
Iterator<Map.Entry<Integer, Integer>> it = entrySet.iterator();
while (it.hasNext()) {
Map.Entry<Integer, Integer> me = it.next();
Integer value = me.getValue();
System.out.println(value);
}
sc.close();
}
}