#include <bits/stdc++.h>
using namespace std;
const int NR = 5000;
int n, m;
long long x[NR + 1];
struct T {
  long long p, c;
  bool operator<(const T &b) const { return p < b.p; }
} a[NR + 1];
int q[NR + 1], head, tail;
long long dp[NR + 1][NR + 1];
long long s[NR + 1];
inline long long val(int x, int y) { return dp[x][y - 1] - s[x]; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", x + i);
  for (int i = 1; i <= m; i++) scanf("%lld%lld", &a[i].p, &a[i].c);
  sort(x + 1, x + n + 1);
  sort(a + 1, a + m + 1);
  long long sum = 0;
  for (int i = 1; i <= m; i++) sum += a[i].c;
  if (sum < n) {
    printf("-1\n");
    return 0;
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i <= m; i++) dp[0][i] = 0;
  for (int j = 1; j <= m; j++) {
    head = 1, tail = 0;
    q[++tail] = 0;
    s[0] = 0;
    for (int i = 1; i <= n; i++) s[i] = s[i - 1] + abs(a[j].p - x[i]);
    for (int i = 1; i <= n; i++) {
      while (head <= tail && q[head] < i - a[j].c) head++;
      while (head <= tail && val(i, j) <= val(q[tail], j)) tail--;
      q[++tail] = i;
      if (head <= tail) dp[i][j] = val(q[head], j) + s[i];
    }
  }
  printf("%lld\n", dp[n][m]);
  return 0;
}
