#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[5005], h[5005], c[5005], q[5005];
long long sum[5005][5005];
long long f[2][5005];
pair<int, int> b[5005];
int read() {
  char c = getchar();
  int x = 0, s = 1;
  while (!isdigit(c)) {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * s;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) p[i] = read();
  for (int i = 1; i <= m; ++i) {
    b[i].first = read();
    b[i].second = read();
  }
  sort(p + 1, p + n + 1);
  sort(b + 1, b + m + 1);
  for (int i = 1; i <= m; ++i) {
    h[i] = b[i].first;
    c[i] = b[i].second;
  }
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) sum[i][j] = sum[i][j - 1] + abs(h[i] - p[j]);
  memset(f[0], 0x3f, sizeof(f[0]));
  f[0][0] = 0;
  for (int i = 1; i <= m; ++i) {
    int cur = i & 1, last = cur ^ 1;
    memset(f[cur], 0x3f, sizeof(f[cur]));
    f[cur][0] = 0;
    int head = 1, tail = 1;
    for (int j = 1; j <= n; ++j) {
      while (head <= tail && q[head] < j - c[i]) ++head;
      while (head <= tail &&
             f[last][j] - sum[i][j] < f[last][q[tail]] - sum[i][q[tail]])
        --tail;
      q[++tail] = j;
      f[cur][j] = f[last][q[head]] + sum[i][j] - sum[i][q[head]];
    }
  }
  if (f[m & 1][n] > (long long)1e18)
    puts("-1");
  else
    printf("%lld\n", f[m & 1][n]);
}
