#include <bits/stdc++.h>
template <typename T1, typename T2>
inline void chmin(T1 &x, T2 b) {
  if (b < x) x = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &x, T2 b) {
  if (b > x) x = b;
}
const int inf = 1039074182;
using namespace std;
long long dp[5005][5005];
pair<long long, int> que[5005];
int l, r;
int n, m;
int hole[5005];
int cap[5005];
int mice[5005];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", mice + i);
  }
  sort(mice, mice + n);
  vector<pair<int, int> > vSort(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", hole + i, cap + i);
    vSort[i] = make_pair(hole[i], cap[i]);
  }
  sort(vSort.begin(), vSort.end());
  for (int i = 0; i < m; i++) {
    hole[i] = vSort[i].first;
    cap[i] = vSort[i].second;
  }
  memset(dp, 0x3f, sizeof(dp));
  long long llinf = dp[0][0];
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    dp[i][0] = 0;
    l = r = 0;
    que[r++] = make_pair(0, 0);
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      sum += abs(hole[i - 1] - mice[j - 1]);
      long long newValue = dp[i - 1][j] - sum;
      while (l != r && que[r - 1].first >= newValue) r--;
      que[r++] = make_pair(newValue, j);
      while (l != r && j - que[l].second > cap[i - 1]) l++;
      assert(l != r);
      dp[i][j] = que[l].first + sum;
    }
  }
  cout << (dp[m][n] == llinf ? -1 : dp[m][n]) << endl;
  return 0;
}
