#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
void solve() {
  int s, b;
  cin >> s >> b;
  vector<int> query(s);
  for (int i = 0; i < int(query.size()); ++i) cin >> query[i];
  vector<pair<int, int> > w(b);
  for (int i = 0; i < int(b); ++i) cin >> w[i].first >> w[i].second;
  sort(w.begin(), w.end());
  vector<int> f(b + 1);
  for (int i = 1; i < int(b + 1); ++i) f[i] = f[i - 1] + w[i - 1].second;
  vector<int> d(b);
  for (int i = 0; i < int(b); ++i) d[i] = w[i].first;
  for (int i = 0; i < int(s); ++i)
    cout << f[upper_bound(d.begin(), d.end(), query[i]) - d.begin()] << " ";
  cout << endl;
}
int main() {
  solve();
  return 0;
}
