One day Masha came home and noticed n mice in the corridor of her flat. Of course, she shouted loudly, so scared mice started to run to the holes in the corridor.

The corridor can be represeted as a numeric axis with n mice and m holes on it. ith mouse is at the coordinate xi, and jth hole — at coordinate pj. jth hole has enough room for cj mice, so not more than cj mice can enter this hole.

What is the minimum sum of distances that mice have to go through so that they all can hide in the holes? If ith mouse goes to the hole j, then its distance is |xi - pj|.

Print the minimum sum of distances.

Input

The first line contains two integer numbers n, m (1 ≤ n, m ≤ 5000) — the number of mice and the number of holes, respectively.

The second line contains n integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the coordinate of ith mouse.

Next m lines contain pairs of integer numbers pj, cj ( - 109 ≤ pj ≤ 109, 1 ≤ cj ≤ 5000), where pj is the coordinate of jth hole, and cj is the maximum number of mice that can hide in the hole j.

Output

Print one integer number — the minimum sum of distances. If there is no solution, print -1 instead.

Examples

Input

4 5
6 2 8 9
3 6
2 1
3 6
4 7
4 7


Output

11


Input

7 2
10 20 30 40 50 45 35
-1000000000 10
1000000000 1


Output

7000000130
//package educational.round19;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

// 1621
public class FX {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni(), m = ni();
		int[] rats = na(n);
		
		int[][] holes = new int[m][];
		for(int i = 0;i < m;i++){
			holes[i] = na(2);
		}
		Arrays.sort(holes, (x, y) -> x[0] - y[0]);
		{
			int o = 0;
			for(int i = 0;i < m;i++){
				if(i == 0 || holes[i][0] != holes[i-1][0]){
					holes[o++] = holes[i];
				}else{
					holes[o-1][1] += holes[i][1];
				}
			}
			holes = Arrays.copyOf(holes, o);
			m = o;
		}
		
		int[] xs = new int[n+m];
		int p = 0;
		int q = 0;
		int[] hxs = new int[m];
		for(int i = 0;i < n;i++){
			xs[p++] = rats[i];
		}
		for(int i = 0;i < m;i++){
			xs[p++] = holes[i][0];
			hxs[q++] = holes[i][0];
		}
		Arrays.sort(xs);
		xs = uniq(xs);
		Arrays.sort(hxs);
		
		long[] fs = new long[xs.length];
		int[] cap = new int[m];
		long ans = 0;
		for(int r : rats){
			int rid = Arrays.binarySearch(xs, r);
			int hid = Arrays.binarySearch(hxs, r);
			long mincost = Long.MAX_VALUE;
			int arg = -1;
			int dir = 0;
			
			long cost = 0;
			for(int i = rid-1, j = hid >= 0 ? hid-1 : -hid-2;i >= 0 && j >= 0;i--){
				cost += (fs[i] > 0 ? -1 : 1) * (xs[i+1] - xs[i]);
				if(hxs[j] == xs[i]){
					if(cost < mincost && cap[j] < holes[j][1]){
						mincost = cost;
						arg = j;
						dir = -1;
					}
					j--;
				}
			}
			cost = 0;
			for(int i = rid+1, j = hid >= 0 ? hid+1 : -hid-1;i < xs.length && j < m;i++){
				cost += (fs[i-1] >= 0 ? 1 : -1) * (xs[i] - xs[i-1]);
				if(hxs[j] == xs[i]){
					if(cost < mincost && cap[j] < holes[j][1]){
						mincost = cost;
						arg = j;
						dir = 1;
					}
					j++;
				}
			}
			if(hid >= 0 && cap[hid] < holes[hid][1]){
				if(0 < mincost){
					mincost = 0;
					arg = hid;
					dir = 0;
				}
			}
			ans += mincost;
			if(arg == -1){
				out.println(-1);
				return;
			}
			cap[arg]++;
			if(dir == -1){
				for(int i = rid-1;i >= 0 && xs[i] >= hxs[arg];i--){
					fs[i]--;
				}
			}else if(dir == 1){
				for(int i = rid;i < xs.length && xs[i] < hxs[arg];i++){
					fs[i]++;
				}
			}
		}
		out.println(ans);
	}
	
	public static int[] uniq(int[] a)
	{
		int n = a.length;
		int p = 0;
		for(int i = 0;i < n;i++) {
			if(i == 0 || a[i] != a[i-1])a[p++] = a[i];
		}
		return Arrays.copyOf(a, p);
	}

	
	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception { new FX().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
