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. *i*th mouse is at the coordinate *x*<sub class="lower-index">*i*</sub>, and *j*th hole — at coordinate *p*<sub class="lower-index">*j*</sub>. *j*th hole has enough room for *c*<sub class="lower-index">*j*</sub> mice, so not more than *c*<sub class="lower-index">*j*</sub> 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 *i*th mouse goes to the hole *j*, then its distance is |*x*<sub class="lower-index">*i*</sub> - *p*<sub class="lower-index">*j*</sub>|.

Print the minimum sum of distances.
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 *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*n*</sub> ( - 10<sup class="upper-index">9</sup> ≤ *x*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>), where *x*<sub class="lower-index">*i*</sub> is the coordinate of *i*th mouse.

Next *m* lines contain pairs of integer numbers *p*<sub class="lower-index">*j*</sub>, *c*<sub class="lower-index">*j*</sub> ( - 10<sup class="upper-index">9</sup> ≤ *p*<sub class="lower-index">*j*</sub> ≤ 10<sup class="upper-index">9</sup>, 1 ≤ *c*<sub class="lower-index">*j*</sub> ≤ 5000), where *p*<sub class="lower-index">*j*</sub> is the coordinate of *j*th hole, and *c*<sub class="lower-index">*j*</sub> is the maximum number of mice that can hide in the hole *j*.
none
4 5
6 2 8 9
3 6
2 1
3 6
4 7
4 7
11
7 2
10 20 30 40 50 45 35
-1000000000 10
1000000000 1
7000000130
1 1
1
1 1
0
1 1
1
1 5000
0
1 1
1000000000
-1000000000 1
2000000000
1 1
-1000000000
1000000000 1
2000000000
2 1
1 1
1 1
-1
2 1
1 1
1 2
0
2 1
1 1
1 5000
0
2 1
1 10
1 2
9
2 1
1 10
7 2
9
2 1
1 10
-7 2
25
2 1
1 10
117 2
223
10 10
-2 3 -7 3 9 -9 3 9 -8 -2
8 1
-2 4
3 2
9 1
7 1
6 3
-4 2
2 2
1 2
4 2
16
5 20
301 332 886 527 923
847 1
-267 1
349 1
-688 1
12 1
214 1
27 1
934 1
383 1
317 1
-426 1
991 1
104 1
609 1
230 1
932 1
-317 1
-857 1
294 1
-451 1
152
100 20
23 -44 6 62 -7 -68 -98 -25 -37 92 89 -100 -14 -4 -35 -76 17 -97 -96 -87 -47 -41 23 37 54 -5 1 13 93 -84 -77 46 55 89 7 57 76 -72 11 48 -15 42 -51 26 53 -56 -100 2 28 -85 -80 97 -53 88 68 66 -13 67 -28 -98 -77 71 -15 24 26 50 60 -9 -9 43 86 -82 -86 60 -85 18 -1 -24 -1 38 65 94 17 -68 18 -28 -51 73 19 53 69 29 25 65 44 79 31 32 -34 -76
11 5
-7 11
-14 8
16 7
-75 8
40 6
-27 9
90 4
7 4
31 8
-79 8
32 7
7 5
4 10
-35 7
57 3
-20 5
21 5
-27 8
-97 5
1284
1 1
2
2 2
0
1 2
2
-1 1
-3 1
3
1 3
-1
3 1
0 1
4 1
1
1 4
4
0 1
5 1
3 1
-4 1
1
1 5
-4
5 1
5 1
1 1
1 1
1 1
5
2 1
-2 3
-3 1
-1
2 2
-4 2
3 3
1 1
6
2 3
3 0
-3 1
4 1
-4 1
4
2 4
-3 3
2 1
5 1
3 1
0 1
3
2 5
4 -7
-7 1
7 1
1 1
-1 1
4 1
0
3 1
3 -4 -3
2 6
12
3 2
-1 -5 4
4 1
-5 1
-1
3 3
-2 2 4
0 1
1 1
-2 1
5
3 4
-3 2 3
1 1
-4 1
5 1
2 1
3
3 5
5 -3 1
-7 1
6 1
-5 1
6 1
-5 1
8
4 1
2 4 5 -5
-2 7
20
4 2
-6 -3 3 4
1 4
-5 4
8
4 3
-7 5 -2 -1
5 2
6 2
4 1
25
4 4
-8 0 -8 -1
0 1
-2 1
-5 1
5 1
15
4 5
4 7 -2 -7
2 1
-3 1
-9 1
6 1
5 1
5
5 1
4 -4 3 -3 0
-3 4
-1
5 2
3 -7 7 1 3
-1 2
-1 1
-1
5 3
-3 1 -7 2 4
-7 2
6 1
5 2
13
5 4
-9 -8 0 0 -8
7 3
-2 2
-1 1
3 1
30
5 5
2 6 -2 1 -6
0 1
2 1
-7 2
-1 1
4 1
5
6 6
-1000000000 -999999999 -999999985 999999996 -999999990 -999999983
999999983 2
-999999997 1
999999983 1
-999999997 1
999999992 1
999999983 1
5999999916
from collections import defaultdict, deque
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
x = [0] + x
d = defaultdict(lambda : 0)
s = 0
for _ in range(m):
    p, c = map(int, input().split())
    d[p] += c
    s += c
if s < n:
    ans = -1
    print(ans)
    exit()
y = list(d.keys())
y.sort()
inf = pow(10, 15) + 1
dp0 = [inf] * (n + 1)
dp0[0] = 0
u = [0] * (n + 1)
s = 0
for i in y:
    l = d[i]
    s += l
    s = min(s, n)
    dp = [inf] * (n + 1)
    dp[0] = 0
    q = deque()
    q.append(0)
    for j in range(1, s + 1):
        u[j] = u[j - 1] + abs(i - x[j])
        while q and j - q[0] > l:
            q.popleft()
        while q and dp0[q[-1]] + u[j] - u[q[-1]] >= dp0[j]:
            q.pop()
        q.append(j)
        dp[j] = dp0[q[0]] + u[j] - u[q[0]]
    dp0 = dp
ans = dp[n]
print(ans)