#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 10;
struct {
  long long num, val;
} q[maxn];
long long f[maxn][maxn], sum[maxn];
int n, m, h, t, cnt, rat[maxn];
pair<int, int> hol[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &rat[i]);
  for (int i = 1, p, c; i <= m; i++) {
    scanf("%d%d", &p, &c);
    cnt += c;
    hol[i] = make_pair(p, c);
  }
  if (cnt < n) return printf("-1") * 0;
  sort(rat + 1, rat + n + 1);
  sort(hol + 1, hol + m + 1);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) f[i][j] = 1e16;
  for (int i = 0; i <= m; i++) f[0][i] = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++)
      sum[i] =
          sum[i - 1] + (rat[i] - hol[j].first > 0 ? rat[i] - hol[j].first
                                                  : -(rat[i] - hol[j].first));
    h = 1;
    t = 0;
    q[++t] = {0, f[0][j - 1]};
    for (int i = 1; i <= n; i++) {
      for (; i - q[h].num > hol[j].second && h <= t; h++)
        ;
      for (; q[t].val > f[i][j - 1] - sum[i] && h <= t; t--)
        ;
      q[++t] = {i, f[i][j - 1] - sum[i]};
      f[i][j] = min(f[i][j], q[h].val + sum[i]);
    }
  }
  printf("%lld", f[n][m]);
  return 0;
}
