#include <bits/stdc++.h>
using namespace std;
const int maxn = 5100;
const long long INF = 1e18;
long long dp[maxn][maxn];
long long sum[maxn] = {0};
long long a[maxn];
long long pre[maxn] = {0};
long long que[maxn];
int beg;
int ed;
struct node {
  long long pos;
  long long c;
};
bool cmp(node a, node b) { return a.pos < b.pos; };
node s[maxn];
int main() {
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxn; j++) dp[i][j] = INF;
  int N;
  int M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> a[i];
  sort(a + 1, a + 1 + N);
  for (int i = 1; i <= M; i++) cin >> s[i].pos >> s[i].c;
  sort(s + 1, s + 1 + M, cmp);
  for (int i = 1; i <= M; i++) pre[i] = pre[i - 1] + s[i].c;
  if (pre[M] < N) {
    cout << -1 << endl;
    return 0;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= M; i++) {
    dp[i][0] = 0;
    beg = 0;
    ed = 0;
    que[ed++] = 0;
    for (int j = 1; j <= pre[i] && j <= N; j++) {
      dp[i][j] = dp[i - 1][j];
      sum[j] = sum[j - 1] + llabs(a[j] - s[i].pos);
      while (beg < ed && j - que[beg] > s[i].c) beg++;
      while (beg < ed &&
             dp[i - 1][que[ed - 1]] - sum[que[ed - 1]] >= dp[i - 1][j] - sum[j])
        ed -= 1;
      que[ed++] = j;
      dp[i][j] = min(dp[i][j], dp[i - 1][que[beg]] - sum[que[beg]] + sum[j]);
    }
  }
  cout << dp[M][N] << endl;
  return 0;
}
