#include <bits/stdc++.h>
using namespace std;
const long long ___ = 0x3f3f3f3f3f3f3f3f;
struct Node {
  int pos, sum;
} holes[5005];
int n, m;
int a[5005];
long long dp[5005][5005];
long long dis[5005];
int q[5005], l, r, sm;
long long val[5005];
bool cmp(Node x, Node y) { return x.pos < y.pos; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= m; i++) scanf("%d%d", &holes[i].pos, &holes[i].sum);
  sort(holes + 1, holes + m + 1, cmp);
  for (int i = 1; i <= n; i++) dp[i][0] = ___;
  for (int i = 1; i <= m; i++) {
    sm += holes[i].sum;
    for (int j = 1; j <= n; j++) dis[j] = abs(holes[i].pos - a[j]) + dis[j - 1];
    l = 0, r = -1;
    for (int j = 0; j <= n; j++) {
      while (l <= r && q[l] < j - holes[i].sum) l++;
      while (l <= r && dp[j][i - 1] - dis[j] <= val[r]) r--;
      q[++r] = j, val[r] = dp[j][i - 1] - dis[j];
      if (sm >= j)
        dp[j][i] = dis[j] + val[l];
      else
        dp[j][i] = ___;
    }
  }
  printf("%lld\n", dp[n][m] == ___ ? -1 : dp[n][m]);
  return 0;
}
