#include <bits/stdc++.h>
using namespace std;
struct mouse {
  int pos, num;
  bool operator<(const mouse& x) const { return pos < x.pos; }
} a[5100];
int n, m, S, head, tail;
int b[5100], q[5100];
long long sum[5100], dp[5100][5100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].pos, &a[i].num);
    S += a[i].num;
  }
  if (S < n) return printf("-1\n"), 0;
  sort(a + 1, a + m + 1);
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++) dp[0][i] = 1e16;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) sum[j] = sum[j - 1] + abs(a[i].pos - b[j]);
    head = 1;
    tail = 0;
    for (int j = 0; j <= n; j++) {
      while (head <= tail && a[i].num < j - q[head]) head++;
      while (head <= tail &&
             dp[i - 1][j] - sum[j] <= dp[i - 1][q[tail]] - sum[q[tail]])
        tail--;
      q[++tail] = j;
      dp[i][j] = dp[i - 1][q[head]] - sum[q[head]] + sum[j];
    }
  }
  printf("%I64d\n", dp[m][n]);
  return 0;
}
