#include <bits/stdc++.h>
using namespace std;
int n, m, x[5000];
long long dp[5001][5000];
pair<int, int> h[5001];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", x + i);
  sort(x, x + n);
  for (int i = 0; i < (int)(n); ++i) dp[0][i] = 1e18;
  int can = 0;
  for (int i = 1; i < (int)(m + 1); ++i)
    scanf("%d%d", &h[i].first, &h[i].second), can += h[i].second;
  if (can < n) printf("-1\n"), exit(0);
  sort(h + 1, h + m + 1);
  for (int i = 1; i < (int)(m + 1); ++i) {
    int p = h[i].first, c = h[i].second;
    deque<pair<long long, int> > q;
    long long z = 0;
    q.push_back(make_pair(0, -1));
    for (int j = 0; j < (int)(n); ++j) {
      z += abs(x[j] - p);
      long long d = dp[i - 1][j] - z;
      while (!q.empty() && q.back().first >= d) q.pop_back();
      q.push_back(make_pair(d, j));
      while (q.front().second < j - c) q.pop_front();
      dp[i][j] = q.front().first + z;
    }
  }
  long long an = 1e18;
  for (int i = 1; i < (int)(m + 1); ++i) an = min(an, dp[i][n - 1]);
  printf("%lld\n", an);
}
