#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const long long inf = 1e15;
bool flag = 1;
int n, m, tot = 0;
long long w, sumc = 0, ans = 0;
struct hole {
  int c, flag;
  long long p;
} o[N];
struct xd {
  int i;
  long long z;
  bool operator<(const xd &a) const { return z > a.z; }
} tmp, nw;
priority_queue<xd> q;
priority_queue<long long, vector<long long>, greater<long long> > q2;
inline int read() {
  int T = 0, F = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') F = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    T = (T << 3) + (T << 1) + (ch - 48), ch = getchar();
  return F * T;
}
bool cmp(hole u, hole v) { return u.p < v.p; }
int main() {
  n = read(), m = read();
  for (register int i = 1; i <= n; ++i)
    ++tot, o[tot].p = read(), o[tot].flag = 0;
  for (register int i = 1; i <= m; ++i) {
    ++tot, o[tot].p = read(), o[tot].c = read(), o[tot].flag = 1,
           sumc += o[tot].c;
    if (o[tot].c != n) flag = 0;
  }
  if (sumc < n) {
    printf("-1\n");
    return 0;
  }
  if (flag) {
    tot = n, sort(o + 1, o + n + 1, cmp), sort(o + n + 1, o + n + m + 1, cmp);
    for (register int i = 1; i <= n; ++i) {
      while (o[i].p >= o[tot + 1].p && tot < n + m) ++tot;
      if (tot >= n + m)
        ans += o[i].p - o[tot].p;
      else if (tot <= n)
        ans += o[tot + 1].p - o[i].p;
      else
        ans += min(o[i].p - o[tot].p, o[tot + 1].p - o[i].p);
    }
    printf("%lld\n", ans);
    return 0;
  }
  sort(o + 1, o + tot + 1, cmp);
  for (register int i = 1; i <= tot; ++i) {
    if (!o[i].flag) {
      w = inf;
      if (!q.empty()) {
        tmp = q.top(), w = o[i].p + tmp.z, q.pop();
        if (o[tmp.i].c) --o[tmp.i].c, q.push(tmp);
      }
      ans += w, q2.push(-o[i].p - w);
    } else {
      while (o[i].c && !q2.empty() && o[i].p + q2.top() < 0)
        --o[i].c, w = o[i].p + q2.top(), q2.pop(), ans += w,
                  tmp.z = -o[i].p - w, tmp.i = 0, q.push(tmp);
      if (o[i].c) --o[i].c, tmp.z = -o[i].p, tmp.i = i, q.push(tmp);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
