#include <bits/stdc++.h>
using namespace std;
int x[5005], q[5005];
long long f[5005][5005], s[5005];
struct hole {
  int p, c;
  bool operator<(const hole &ano) const { return p < ano.p; }
} h[5005];
int main() {
  int i, j, k;
  int n, m, sum = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", x + i);
  sort(x + 1, x + n + 1);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &h[i].p, &h[i].c);
    sum += h[i].c;
  }
  sort(h + 1, h + m + 1);
  if (sum < n) {
    printf("-1");
    return 0;
  }
  int l, r;
  for (i = 1; i <= n; i++) f[0][i] = (long long)1e14;
  for (i = 1; i <= m; i++) {
    l = 1;
    r = 0;
    q[++r] = 0;
    for (j = 1; j <= n; j++) {
      s[j] = s[j - 1] + abs(x[j] - h[i].p);
      while (r && f[i - 1][q[r]] - s[q[r]] >= f[i - 1][j] - s[j]) r--;
      q[++r] = j;
      while (j - q[l] > h[i].c) l++;
      f[i][j] = s[j] + f[i - 1][q[l]] - s[q[l]];
    }
  }
  printf("%I64d", f[m][n]);
  return 0;
}
