#include <bits/stdc++.h>
using namespace std;
long long s, b, d, g, psum[100004], temp, real_ret[100004];
vector<pair<int, int>> a, ret;
int main() {
  cin >> s >> b;
  for (int i = 0; i < s; i++) {
    cin >> temp;
    ret.push_back({temp, i});
  }
  for (int i = 0; i < b; i++) {
    cin >> d >> g;
    a.push_back({d, g});
  }
  sort(ret.begin(), ret.end());
  sort(a.begin(), a.end());
  psum[0] = a[0].second;
  for (int i = 1; i < b; i++) {
    psum[i] = psum[i - 1] + a[i].second;
  }
  long long cnt = 0, idx = 0, _ret = 0;
  for (int i = 0; i < s; i++) {
    for (int j = idx; j < b; j++) {
      if (a[j].first > ret[i].first) {
        break;
      } else {
        idx++;
        _ret = psum[j];
      }
    }
    real_ret[ret[i].second] = _ret;
  }
  for (int i = 0; i < s; i++) {
    cout << real_ret[i] << "\n";
  }
  return 0;
}
