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;
namespace baseFastio {
template <typename Int>
inline Int read() {
  Int flag = 1;
  char c = getchar();
  while ((!isdigit(c)) && c != '-' && c != EOF) c = getchar();
  if (c == '-') flag = -1, c = getchar();
  Int init = c & 15;
  while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
  return init * flag;
}
template <typename Int>
inline Int read(char& c) {
  Int flag = 1;
  c = getchar();
  while ((!isdigit(c)) && c != '-' && c != EOF) c = getchar();
  if (c == '-') flag = -1, c = getchar();
  Int init = c & 15;
  while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
  return init * flag;
}
template <typename Int>
inline void write(Int x) {
  if (x < 0) putchar('-'), x = ~x + 1;
  if (x > 9) write(x / 10);
  putchar((x % 10) | 48);
}
template <typename Int>
inline void write(Int x, char nextch) {
  write(x);
  putchar(nextch);
}
}  // namespace baseFastio
namespace Fastio {
enum io_flags { ignore_int = 1 << 0 };
struct Reader {
  char endch;
  Reader() { endch = '\0'; }
  template <typename Int>
  Int operator()() {
    return baseFastio::read<Int>(endch);
    ;
  }
  Reader& operator>>(io_flags f) {
    if (f == ignore_int) baseFastio::read<int>();
    return *this;
  }
  template <typename Int>
  Reader& operator>>(Int& i) {
    i = baseFastio::read<Int>(endch);
    return *this;
  }
  template <typename Int>
  inline Int get_int() {
    return baseFastio::read<Int>();
  }
  inline char get_nxt() { return endch; }
} read;
struct Writer {
  Writer& operator<<(const char* ch) {
    while (*ch) putchar(*(ch++));
    return *this;
  }
  Writer& operator<<(const char ch) {
    putchar(ch);
    return *this;
  }
  template <typename Int>
  Writer& operator<<(const Int i) {
    baseFastio::write(i);
    return *this;
  }
} write;
}  // namespace Fastio
using namespace Fastio;
namespace against_cpp11 {
const int N = 5e3 + 7;
int n, m;
struct mouse_and_hole {
  int x, y;
  bool operator<(const mouse_and_hole& b) const { return x < b.x; }
} p[N * 2];
vector<int> hole[N];
struct st {
  long long w;
  int id;
  bool operator<(const st& b) const { return w > b.w; }
};
priority_queue<long long, vector<long long>, greater<long long> > q1;
priority_queue<st> q2;
long long w, ans;
int count_hole_room = 0;
signed main() {
  read >> n >> m;
  for (int i = 1; i <= n; i++) {
    read >> p[i].x;
    p[i].y = -1;
  }
  for (int i = 1; i <= m; i++) {
    read >> p[i + n].x >> p[i + n].y;
    count_hole_room += p[i + n].y;
  }
  if (count_hole_room < n) {
    puts("-1");
    return 0;
  }
  n += m;
  sort(p + 1, p + n + 1);
  for (int i = 1, k; i <= n; i++)
    if (p[i].y == -1) {
      w = INT_MAX;
      if (!q2.empty()) {
        k = q2.top().id;
        w = p[i].x + q2.top().w;
        q2.pop();
        if (p[k].y) p[k].y--, q2.push((st){-p[k].x, k});
      }
      ans += w;
      q1.push(-p[i].x - w);
    } else {
      while (p[i].y && !q1.empty() && p[i].x + q1.top() < 0) {
        p[i].y--;
        w = p[i].x + q1.top();
        q1.pop();
        ans += w;
        q2.push((st){-p[i].x - w, 0});
      }
      if (p[i].y) q2.push((st){-p[i].x, i}), p[i].y--;
    }
  write << ans << '\n';
  return 0;
}
}  // namespace against_cpp11
signed main() { return against_cpp11::main(); }