#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
long long f[maxn][maxn], s[maxn];
int n, m, q[maxn], x[maxn], p[maxn], c[maxn], r[maxn];
int cmp(int a, int b) { return p[a] < p[b]; }
void Init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  sort(x + 1, x + n + 1);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &p[i], &c[i]), r[i] = i;
  sort(r + 1, r + m + 1, cmp);
  for (int i = 0; i <= m; ++i)
    for (int j = 1; j <= n; ++j) f[i][j] = 1ll << 50;
}
int main() {
  Init();
  for (int i = 1, st, en, num; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) s[j] = s[j - 1] + abs(x[j] - p[r[i]]);
    num = c[r[i]];
    q[st = en = 1] = 0;
    for (int j = 1; j <= n; ++j) {
      while (q[st] < j - num && st < en) ++st;
      while (st <= en && f[i - 1][q[en]] - s[q[en]] >= f[i - 1][j] - s[j]) --en;
      q[++en] = j;
      f[i][j] = f[i - 1][q[st]] + s[j] - s[q[st]];
    }
  }
  printf("%I64d\n", f[m][n] == f[0][1] ? -1ll : f[m][n]);
  return 0;
}
