Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi reminded him that last year's HC2 theme was Star Wars. Now he understood, and he's ready to face the evils of the Empire!

The rebels have s spaceships, each with a certain attacking power a.

They want to send their spaceships to destroy the empire bases and steal enough gold and supplies in order to keep the rebellion alive.

The empire has b bases, each with a certain defensive power d, and a certain amount of gold g.

A spaceship can attack all the bases which have a defensive power less than or equal to its attacking power.

If a spaceship attacks a base, it steals all the gold in that base.

The rebels are still undecided which spaceship to send out first, so they asked for the Doctor's help. They would like to know, for each spaceship, the maximum amount of gold it can steal.

Input

The first line contains integers s and b (1 ≤ s, b ≤ 10^5), the number of spaceships and the number of bases, respectively.

The second line contains s integers a (0 ≤ a ≤ 10^9), the attacking power of each spaceship.

The next b lines contain integers d, g (0 ≤ d ≤ 10^9, 0 ≤ g ≤ 10^4), the defensive power and the gold of each base, respectively.

Output

Print s integers, the maximum amount of gold each spaceship can steal, in the same order as the spaceships are given in the input.

Example

Input


5 4
1 3 5 2 4
0 1
4 2
2 8
9 4


Output


1 9 11 9 11

Note

The first spaceship can only attack the first base.

The second spaceship can attack the first and third bases.

The third spaceship can attack the first, second and third bases.
#include <bits/stdc++.h>
const long long mod = 1000000007, smod = 1073741824, pmod = 998244353,
                N = 1e6 + 9;
const long double pi = 3.1415926536;
using namespace std;
vector<long long> v;
string lin;
void split() {
  for (int i = lin.size() - 1; i >= 0; i--) {
    long long num = 0;
    int push = 1;
    while (lin[i] != ' ' && i >= 0) {
      num += (lin[i] - '0') * push;
      push *= 10;
      i--;
    }
    if (num) v.push_back(num);
  }
}
long long llnCr(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n == k || n == 0) return 1;
  return (n * llnCr(n - 1, k) % mod) / (n - k);
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  long long q = a % b;
  if (!q) return b;
  return gcd(b, q);
}
int totgcd(int s, int n) {
  if (s == n - 2) return gcd(v[n - 2], v[n - 1]);
  return gcd(v[s], totgcd(s + 1, n));
}
long long power(long long x, long long num) {
  long long ans = 1;
  for (int i = 0; i < num; i++) {
    ans *= x;
    ans = ans % mod;
  }
  return ans;
}
void movestep(long long& a, long long& b, long long q) {
  long long next = a - (q * b);
  a = b;
  b = next;
}
long long Egcd(long long a, long long b, long long& x0, long long& y0) {
  long long r0 = a, r1 = b;
  long long x1, y1;
  x1 = y0 = 0;
  x0 = y1 = 1;
  while (r1 != 0) {
    long long q = r0 / r1;
    movestep(x0, x1, q);
    movestep(y0, y1, q);
    movestep(r0, r1, q);
  }
  return r0;
}
long long minv(long long f) {
  long long x, y;
  long long g = Egcd(f, mod, x, y);
  if (g != 1)
    return -1;
  else
    return (x + mod) % mod;
}
long long fact[N], inv[N];
long long ftpr(long long k, long long m) {
  if (!m) return 1;
  long long ans = ftpr(k, m / 2);
  ans = (ans * ans) % mod;
  if (m % 2) ans = (ans * (k % mod)) % mod;
  return ans;
}
void pre(int x) {
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= x; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = ftpr(fact[i], mod - 2);
  }
}
long long combination(long long n, long long r) {
  long long fo2 = fact[n];
  long long t7t = inv[r] * inv[n - r] % mod;
  return fo2 * t7t % mod;
}
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int x, y, push, g;
  cin >> x >> y;
  vector<long long> v(x);
  vector<pair<int, int> > v2(y);
  for (int i = 0; i < x; i++) cin >> v[i];
  for (int i = 0; i < y; i++) {
    cin >> push >> g;
    v2[i] = (make_pair(push, g));
  }
  sort(v2.begin(), v2.end());
  for (int i = 0; i < x; i++) {
    long long sum = 0;
    for (int j = 0; j < y; j++) {
      if (v2[j].first <= v[i])
        sum += v2[j].second;
      else
        break;
    }
    cout << sum << " ";
  }
  return 0;
}
