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.util.*;
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
public class Solutions {
	 
	static FastScanner scr=new FastScanner();
	static PrintStream out=new PrintStream(System.out);
//	static ArrayList<ArrayList<Integer>>list=new ArrayList<ArrayList<Integer>>();
	public static void main(String []args) {
		int n=scr.nextInt();
		int b=scr.nextInt();
		int []a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scr.nextInt();
		}
		for(int i=0;i<b;i++) {
			list.add(new pair(scr.nextInt(),scr.nextInt()));
		}
		Collections.sort(list,new Comparator<pair>() {
			public int compare(pair a,pair b) {
				return a.x-b.x;
			}
		});
		int []preSum=new int[b];
		preSum[0]=list.get(0).y;
		for(int i=1;i<b;i++) {
			preSum[i]+=preSum[i-1]+list.get(i).y;
		}
		for(int i=0;i<n;i++) {
			out.print(bs(preSum,a[i])+" ");
		}
	}
	static int bs(int presum[],int value) {
		int low=0;
		int high=list.size()-1;
		int ans=0;
		while(low<=high) {
			int mid=(low+high)/2;
			if(list.get(mid).x<=value) {
				ans=presum[mid];
				low=mid+1;
			}else {
				high=mid-1;
			}
		}
		return ans;
	}
	static ArrayList<pair>list  =new ArrayList<>();
	static boolean can(int cnt,long a,long b,long k,long n) {
		int cntB=(int) ((k-cnt*a)/b);
		return cntB+cnt>=n;
	}
	static long parse(String s) {
		return Long.parseLong(s);
	}
	static boolean count(int n) {
		if(n<2) {
			return false;
		}
		for(int i=2;i*i<=n;i++) {
			if(n%i==0) {
				return false;
			}
		}
		return true;
	}
	static boolean check(int a[],int b[],int x,int y) {
		for(int i=0;i<a.length;i++) {
			if(a[i]!=x && a[i]!=y && b[i]!=x && b[i]!=y) {
				return false;
			}
		}
		return true;
	}
	static int gcd(int a,int b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	static int MAX=Integer.MAX_VALUE;
	static int MIN=Integer.MIN_VALUE;
}class triplet{
	int x;
	int y;
	int z;
	triplet(int fisrt,int second,int third){
		this.x=fisrt;
		this.y=second;
		this.z=third;
	}
}
class pair{
	int x=0;
	int y=0;
	pair(int first,int second){
		this.x=first;
		this.y=second;
	}
}