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
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXHOLE = 5000;
const int MAXMOUSE = 5000;
const int MAXLG = 12;
int nmouse, nhole;
int cnt[MAXHOLE];
int hole[MAXHOLE];
int mouse[MAXMOUSE];
long long mousesum[MAXMOUSE + 1];
int fst[MAXHOLE];
long long dp[MAXHOLE + 1][MAXMOUSE + 1];
long long v[MAXMOUSE + 1];
int q[MAXMOUSE + 1], qhead, qtail;
long long myadd(long long a, long long b) {
  return a == LLONG_MAX || b == LLONG_MAX ? LLONG_MAX : a + b;
}
pair<int, int> o[MAXHOLE];
void run() {
  scanf("%d%d", &nmouse, &nhole);
  for (int i = (0); i < (nmouse); ++i) scanf("%d", &mouse[i]);
  for (int i = (0); i < (nhole); ++i) scanf("%d%d", &o[i].first, &o[i].second);
  sort(mouse, mouse + nmouse);
  sort(o, o + nhole);
  for (int i = (0); i < (nhole); ++i)
    hole[i] = o[i].first, cnt[i] = o[i].second;
  mousesum[0] = 0;
  for (int i = (0); i < (nmouse); ++i) mousesum[i + 1] = mousesum[i] + mouse[i];
  for (int i = nhole - 1; i >= 0; --i) {
    fst[i] = i == nhole - 1 ? nmouse : fst[i + 1];
    while (fst[i] - 1 >= 0 && mouse[fst[i] - 1] >= hole[i]) --fst[i];
  }
  for (int j = (0); j <= (nmouse); ++j) dp[0][j] = j == 0 ? 0 : LLONG_MAX;
  for (int i = (0); i < (nhole); ++i) {
    for (int j = (0); j <= (nmouse); ++j) dp[i + 1][j] = LLONG_MAX;
    for (int k = (0); k <= (nmouse); ++k)
      v[k] = myadd(dp[i][k], (long long)+k * hole[i] - mousesum[k]);
    qhead = qtail = 0;
    for (int j = (0); j <= (nmouse); ++j) {
      while (qtail < qhead && v[q[qhead - 1]] >= v[j]) --qhead;
      q[qhead++] = j;
      int kmn = max(max(0, j - cnt[i]), fst[i]);
      while (qtail < qhead && q[qtail] < kmn) ++qtail;
      if (fst[i] <= j && qtail < qhead) {
        long long cur =
            myadd(v[q[qtail]], mousesum[j] - (long long)j * hole[i]);
        if (cur < dp[i + 1][j]) dp[i + 1][j] = cur;
      }
    }
    for (int k = (0); k <= (nmouse); ++k)
      v[k] = myadd(dp[i][k], (long long)-k * hole[i] + mousesum[k]);
    qhead = qtail = 0;
    for (int j = (0); j <= (nmouse); ++j) {
      if (j < fst[i]) {
        while (qtail < qhead && v[q[qhead - 1]] >= v[j]) --qhead;
        q[qhead++] = j;
      }
      int kmn = max(0, j - cnt[i]);
      while (qtail < qhead && q[qtail] < kmn) ++qtail;
      if (kmn < fst[i] && fst[i] <= j) {
        long long cur =
            myadd(v[q[qtail]], (long long)fst[i] * hole[i] - mousesum[fst[i]] +
                                   mousesum[j] - mousesum[fst[i]] -
                                   (long long)(j - fst[i]) * hole[i]);
        if (cur < dp[i + 1][j]) dp[i + 1][j] = cur;
      }
      if (j < fst[i]) {
        long long cur =
            myadd(v[q[qtail]], (long long)j * hole[i] - mousesum[j]);
        if (cur < dp[i + 1][j]) dp[i + 1][j] = cur;
      }
    }
  }
  long long ret = dp[nhole][nmouse];
  printf("%lld\n", ret == LLONG_MAX ? -1 : ret);
}
int main() {
  run();
  return 0;
}
