#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, c;
  friend bool operator<(node a, node b) { return a.x < b.x; }
} b[5005];
int n, m, l, r;
int q[5005];
long long a[5005], f[5005][5005], s[5005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld", &b[i].x, &b[i].c);
  }
  sort(b + 1, b + m + 1);
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    f[i][0] = 0;
    q[l = r = 1] = 0;
    for (int j = 1; j <= n; j++) {
      s[j] = s[j - 1] + abs(b[i].x - a[j]);
      while (l <= r && j - q[l] > b[i].c) l++;
      f[i][j] = min(f[i - 1][j], s[j] + f[i - 1][q[l]] - s[q[l]]);
      while (l <= r && f[i - 1][q[r]] - s[q[r]] >= f[i - 1][j] - s[j]) r--;
      q[++r] = j;
    }
  }
  if (f[m][n] >= 0x3f3f3f3f3f3f3f3f)
    puts("-1");
  else
    cout << f[m][n] << endl;
  return 0;
}
