#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
int s, b, ship[MAX_N];
long long pre[MAX_N];
struct Base {
  int d, g;
  inline void input() { scanf("%d%d", &d, &g); }
  friend bool operator<(const Base &x, const Base &y) {
    if (x.d != y.d)
      return x.d < y.d;
    else
      return x.g < y.g;
  }
} base[MAX_N];
int u[MAX_N];
int main() {
  scanf("%d%d", &s, &b);
  for (int i = 1; i <= s; ++i) scanf("%d", ship + i);
  for (int i = 1; i <= b; ++i) base[i].input();
  sort(base + 1, base + b + 1);
  for (int i = 1; i <= b; ++i) u[i] = base[i].d;
  for (int i = 1; i <= b; ++i) {
    pre[i] = pre[i - 1] + base[i].g;
  }
  pre[b + 1] = pre[b];
  for (int i = 1; i <= s; ++i) {
    int v = ship[i];
    int pos = upper_bound(u + 1, u + b + 1, v) - u;
    printf("%lld%c", pre[pos - 1], i == s ? '\n' : ' ');
  }
  return 0;
}
