Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 1e6 + 20;
struct Query {
  int x, d;
  bool operator<(const Query a) const { return x < a.x; }
};
Query qu[maxn * 2];
int n, m;
void init() {
  n = read();
  m = read();
  for (register int i = (1), _end_ = (n); i <= _end_; i++)
    qu[i] = (Query){read(), -1};
  long long s = 0;
  for (register int i = (1), _end_ = (m); i <= _end_; i++) {
    qu[i + n] = (Query){read(), read()};
    s += qu[i + n].d;
  }
  sort(qu + 1, qu + n + m + 1);
  if (s < n) {
    printf("-1\n");
    exit(0);
  }
  n = n + m;
}
struct node {
  long long x;
  int p;
  bool operator<(const node a) const { return x > a.x; }
};
priority_queue<node> q1;
priority_queue<long long, vector<long long>, greater<long long> > q0;
const long long inf = 1ll << 57;
long long ans;
void doing() {
  for (register int i = (1), _end_ = (n); i <= _end_; i++) {
    if (qu[i].d == -1) {
      long long w = inf;
      if (!q1.empty()) {
        w = qu[i].x + q1.top().x;
        int k = q1.top().p;
        q1.pop();
        if (k && qu[k].d) qu[k].d--, q1.push((node){-qu[k].x, k});
      }
      ans += w;
      q0.push(-w - qu[i].x);
    } else {
      while (qu[i].d && !q0.empty() && q0.top() + qu[i].x < 0) {
        long long w = qu[i].x + q0.top();
        q0.pop();
        ans += w;
        qu[i].d--;
        q1.push((node){-w - qu[i].x, 0});
      }
      if (qu[i].d) qu[i].d--, q1.push((node){-qu[i].x, i});
    }
  }
  printf("%lld\n", ans);
}
int main() {
  init();
  doing();
  return 0;
}