#include <bits/stdc++.h>
using namespace std;
inline long long Abs(long long x) { return x < 0 ? -x : x; }
long long n, m;
long long a[5100], f[2][5100];
struct node {
  long long x, c;
} b[5100];
inline bool cmp(node a, node b) { return a.x < b.x; }
inline void init() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", a + i);
  long long totcnt = 0;
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= m; i++)
    scanf("%lld%lld", &b[i].x, &b[i].c), totcnt += b[i].c;
  if (totcnt < n) exit((puts("-1"), 0));
  sort(b + 1, b + m + 1, cmp);
}
long long sum[5100], q[5100 << 1], he, ta;
signed main() {
  init();
  for (long long i = 1; i <= n; i++) f[0][i] = 1e18;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) sum[j] = sum[j - 1] + Abs(a[j] - b[i].x);
    he = 1;
    ta = 0;
    for (long long j = 0; j <= n; j++) {
      while (he <= ta && q[he] < j - b[i].c) he++;
      while (he <= ta &&
             f[(i - 1) & 1][q[ta]] - sum[q[ta]] >= f[(i - 1) & 1][j] - sum[j])
        ta--;
      q[++ta] = j;
      f[i & 1][j] = f[(i - 1) & 1][q[he]] - sum[q[he]] + sum[j];
    }
  }
  printf("%lld", f[m & 1][n]);
  return 0;
}
