#include <bits/stdc++.h>
using namespace std;
long long N;
long long l[5555];
long long r[5555];
long long dp[2][11111];
long long idx[2][11111];
long long minDp[2][11111];
bool in(long long x, vector<int> &w) { return (0 <= x && x < w.size()); }
bool in(long long x, long long l, long long r) { return (l <= x && x < r); }
long long dist(long long x, long long y) { return abs(x - y); }
void getMin(long long i) {
  minDp[i][0] = dp[i][0];
  for (long long j = 1; j < N; j++) {
    minDp[i][j] = min(minDp[i][j - 1], dp[i][j]);
  }
}
int main(void) {
  cin.tie(0);
  cin.sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> x(n);
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> x[i];
  }
  vector<pair<long long, long long> > v(m);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(x.begin(), x.end());
  sort(v.begin(), v.end());
  vector<int> w;
  for (long long i = 0; i < (long long)(m); i++) {
    for (long long j = 0; j < (long long)(v[i].second); j++)
      w.push_back(v[i].first);
  }
  if (x.size() > w.size()) {
    cout << -1 << '\n';
    return 0;
  }
  for (long long i = 0; i < (long long)(n); i++) {
    if (x[i] < w.front()) {
      l[i] = -1;
      r[i] = 0;
      continue;
    }
    if (x[i] > w.back()) {
      l[i] = w.size() - 1;
      r[i] = -1;
      continue;
    }
    long long L = 0;
    long long R = w.size() - 1;
    while (L != R) {
      long long mid = (L + R + 1) >> 1;
      if (w[mid] <= x[i])
        L = mid;
      else
        R = mid - 1;
    }
    l[i] = L;
    r[i] = L + 1;
  }
  N = 2 * n + 1;
  for (long long j = 0; j < (long long)(N); j++) {
    long long k = l[0] - (n - j);
    idx[0][j] = k;
    if (!in(k, w)) {
      dp[0][j] = 1e18;
      continue;
    }
    dp[0][j] = dist(x[0], w[k]);
  }
  getMin(0);
  for (long long I = 1; I < n; I++) {
    long long i = I & 1;
    for (long long j = 0; j < (long long)(N); j++) {
      long long k = l[I] - (n - j);
      idx[i][j] = k;
      dp[i][j] = 1e18;
    }
    for (long long j = idx[!i][0] + 1 - l[I] + n, jdx = 0; j < N; j++, jdx++) {
      if (j < 0 || jdx < 0) continue;
      long long k = l[I] - (n - j);
      if (!in(k, w)) continue;
      dp[i][j] = dist(x[I], w[k]);
      dp[i][j] += minDp[!i][min(jdx, N - 1)];
    }
    getMin(i);
  }
  cout << minDp[(n - 1) & 1][N - 1] << '\n';
  return 0;
}
