#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const long long inf = 1e15;
struct Hole {
  int p, c;
  bool operator<(Hole B) const { return p < B.p; }
} h[maxn];
int m, n, cur;
long long f[2][maxn], sum[maxn];
int x[maxn];
int q[maxn], head, tail;
long long func(int j) { return f[cur ^ 1][j] - sum[j]; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &h[i].p, &h[i].c);
  sort(x + 1, x + n + 1);
  sort(h + 1, h + m + 1);
  sum[0] = f[0][0] = 0;
  for (int i = 1; i <= n; ++i) f[0][i] = inf;
  cur = 0;
  for (int i = 1; i <= m; ++i) {
    cur ^= 1;
    f[cur][0] = 0;
    head = tail = 0;
    q[0] = 0;
    tail++;
    for (int j = 1; j <= n; ++j) {
      sum[j] = sum[j - 1] + abs(x[j] - h[i].p);
      while (head < tail && j - q[head] > h[i].c) head++;
      f[cur][j] = min(f[cur ^ 1][j], func(q[head]) + sum[j]);
      while (head < tail && func(q[tail - 1]) > func(j)) tail--;
      q[tail++] = j;
    }
  }
  if (f[cur][n] >= inf)
    printf("-1\n");
  else
    printf("%lld\n", f[cur][n]);
  return 0;
}
