#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
int n, m;
struct node {
  int x, c;
  bool operator<(const node &b) const { return x < b.x; }
} p[maxn];
int a[maxn];
long long f[maxn][maxn];
long long inf;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= m; i++) scanf("%d%d", &p[i].x, &p[i].c);
  sort(p + 1, p + 1 + m);
  memset(f, 0x7f, sizeof(f));
  inf = f[0][0];
  f[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    int h = 0;
    f[i][0] = 0;
    long long s = 0, now, nxt;
    for (int j = 1; j <= n; j++) {
      s += abs(p[i].x - a[j]);
      now = inf;
      if (f[i - 1][h] != inf && j - h <= p[i].c) now = f[i - 1][h] + s;
      while (h < j) {
        h++;
        s -= abs(p[i].x - a[h]);
        nxt = inf;
        if (f[i - 1][h] != inf) nxt = f[i - 1][h] + s;
        if (now < nxt) {
          s += abs(a[h] - p[i].x);
          h--;
          break;
        }
        now = nxt;
      }
      f[i][j] = now;
    }
  }
  if (f[m][n] == inf)
    printf("-1\n");
  else
    printf("%I64d\n", f[m][n]);
  return 0;
}
