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.
 
import java.io.*;
import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;


public class Main {
    private static AWriter writer = new AWriter(System.out);
    private static AReader reader = new AReader(System.in);
    private static int[][] direct={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}};
    private static int[] a;
    private static int cnt=1;
    private static int m;
    private static int n;
    private static int sword[];
    private static long save[];
    private static List<empire> empires;
    public static void main(String[] args) throws IOException {
       m=reader.nextInt();
       n=reader.nextInt();
       sword=new int[m];
       save=new long[n+1];
       empires=new ArrayList<>();
       for(int i=0;i<m;i++){
           sword[i]=reader.nextInt();
       }
       for(int i=0;i<n;i++){
           empires.add(new empire());
           empires.get(i).def=reader.nextInt();
           empires.get(i).gold=reader.nextInt();
       }
       Collections.sort(empires,(a1,a2)->(int)(a1.def-a2.def));
       save[0]=empires.get(0).gold;
       for(int i=1;i<n;i++){
           save[i]=save[i-1]+empires.get(i).gold;
       }
       for(int i=0;i<m;i++){
           if(empires.get(0).def>sword[i])
               writer.print(0);
           else if(empires.get(n-1).def<sword[i])
               writer.print(save[n-1]);
           else
                writer.print(save[half(i)]);
           if(i!=m-1)
               writer.print(" ");
       }
        reader.close();
        writer.close();
    }
    private static int half(int i){
        int ans=0;
        int r=n-1;
        int l=0;
        while(r>l){
            int mid=(r+l)/2;
            if(sword[i]>=empires.get(mid).def&&sword[i]<empires.get(mid+1).def){
                return mid;
            }
            if(sword[i]<=empires.get(mid).def)
                r=mid;
            else
                l=mid;
        }
        return 0;
    }
}
class empire{
    long def;
    long gold;
}
class AReader implements Closeable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    public AReader(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }
    private String innerNextLine() {
        try {
            return reader.readLine();
        } catch (IOException ex) {
            return null;
        }
    }
    public boolean hasNext() {
        while (!tokenizer.hasMoreTokens()) {
            String nextLine = innerNextLine();
            if (nextLine == null) {
                return false;
            }
            tokenizer = new StringTokenizer(nextLine);
        }
        return true;
    }
    public String nextLine() {
        tokenizer = new StringTokenizer("");
        return innerNextLine();
    }
    public String next() {
        hasNext();
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.valueOf(next());
    }
    public long nextLong() {
        return Long.valueOf(next());
    }
    public double nextDouble() {
        return Double.valueOf(next());
    }
    public BigDecimal nextBigDecimal(){ return new BigDecimal(next()); }
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
    @Override
    public void close() throws IOException {
        reader.close();
    }
}

// Fast writer for ACM By Azure99
class AWriter implements Closeable {
    private BufferedWriter writer;

    public AWriter(OutputStream outputStream) {
        writer = new BufferedWriter(new OutputStreamWriter(outputStream));
    }

    public void print(Object object) throws IOException {
        writer.write(object.toString());
    }

    public void println(Object object) throws IOException {
        writer.write(object.toString());
        writer.write("\n");
    }

    @Override
    public void close() throws IOException {
        writer.close();
    }
}