#include <bits/stdc++.h>
using namespace std;
int n, m, x[5010];
long long dp[2][5010], sum[5010];
struct node {
  long long p;
  int c;
} a[5010];
bool cmp(node a, node b) { return a.p < b.p; }
deque<node> q;
int main() {
  scanf("%d%d", &n, &m);
  int s = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  sort(x + 1, x + n + 1);
  for (int i = 1; i <= m; i++) scanf("%lld%d", &a[i].p, &a[i].c), s += a[i].c;
  if (s < n) return printf("-1"), 0;
  sort(a + 1, a + m + 1, cmp);
  memset(dp, 0x7f, sizeof(dp));
  dp[0][0] = 0;
  long long ans = 1e18;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) sum[j] = sum[j - 1] + abs(x[j] - a[i].p);
    while (!q.empty()) q.pop_front();
    for (int j = 0; j <= n; j++) {
      while (!q.empty() && j - q.front().c > a[i].c) q.pop_front();
      while (!q.empty() && q.front().p >= dp[!(i & 1)][j] - sum[j])
        q.pop_back();
      q.push_back((node){dp[!(i & 1)][j] - sum[j], j});
      dp[i & 1][j] = q.front().p + sum[j];
      dp[!(i & 1)][j] = 1e18;
    }
    ans = min(ans, dp[i & 1][n]);
  }
  return printf("%lld", ans), 0;
}
