#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3f;
using namespace std;
const long long maxn = 5009;
long long read() {
  long long qqq;
  scanf("%lld", &qqq);
  return qqq;
}
long long n, m;
long long pos[maxn];
long long dp[maxn][maxn], sum[maxn], S;
long long q[maxn];
struct node {
  long long pos, num;
  bool operator<(const node& b) const { return pos < b.pos; }
} a[maxn];
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) pos[i] = read();
  sort(pos + 1, pos + 1 + n);
  for (long long i = 1; i <= m; i++) {
    a[i].pos = read(), a[i].num = read(), S += a[i].num;
  }
  sort(a + 1, a + 1 + m);
  if (S < n) {
    puts("-1");
    return 0;
  }
  for (long long i = 1; i <= n; i++) dp[0][i] = inf;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      sum[j] = sum[j - 1] + abs(pos[j] - a[i].pos);
    }
    long long head = 1, tail = 0;
    for (long long j = 0; j <= n; j++) {
      while (head <= tail and q[head] < j - a[i].num) head += 1;
      while (head <= tail and
             dp[i - 1][j] - sum[j] <= dp[i - 1][q[tail]] - sum[q[tail]]) {
        tail -= 1;
      }
      q[++tail] = j;
      dp[i][j] = dp[i - 1][q[head]] - sum[q[head]] + sum[j];
    }
  }
  printf("%lld\n", dp[m][n]);
  return 0;
}
