#include <bits/stdc++.h>
const int N = 5005;
const long long inf = 1000000000000007LL;
using namespace std;
int n, m, he, ta, st[N];
struct poi {
  int x, y;
} a[N], b[N];
long long g[N], val[N], f[N];
bool cmp(poi a, poi b) { return a.x < b.x; }
int abs(int x) { return (x < 0 ? -x : x); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i].x);
  int sum = 0;
  for (int i = 1; i <= m; ++i) scanf("%d%d", &b[i].x, &b[i].y), sum += b[i].y;
  if (sum < n) {
    printf("-1\n");
    return 0;
  }
  sort(a + 1, a + n + 1, cmp);
  sort(b + 1, b + m + 1, cmp);
  for (int i = 1; i <= n; ++i) g[i] = inf;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      val[j] = abs(a[j].x - b[i].x);
      val[j] += val[j - 1];
    }
    he = 1, ta = 1, st[ta] = 0;
    for (int j = 1; j <= n; ++j) {
      for (; he <= ta && st[he] < j - b[i].y; ++he)
        ;
      f[j] = g[st[he]] + val[j] - val[st[he]];
      for (; he <= ta && g[j] - val[j] <= g[st[ta]] - val[st[ta]]; --ta)
        ;
      st[++ta] = j;
    }
    for (int j = 1; j <= n; ++j) g[j] = min(g[j], f[j]);
  }
  printf("%lld\n", g[n]);
  return 0;
}
