#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 5007;
int n, m, x[MAXN];
long long int f[2][MAXN], dis[MAXN];
pair<int, int> hole[MAXN];
pair<long long int, int> que[MAXN];
void solve() {
  ____();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int i = 1; i <= m; i++) cin >> hole[i].first >> hole[i].second;
  sort(x + 1, x + 1 + n);
  sort(hole + 1, hole + 1 + m);
  memset(f, 0x3f, sizeof(f));
  int tag = 1;
  f[0][0] = 0;
  for (int i = 1; i <= m; i++, tag ^= 1) {
    memset(f[tag], 0x3f, sizeof(f[tag]));
    f[tag][0] = 0;
    int d = hole[i].first, c = hole[i].second;
    for (int j = 1; j <= n; j++) dis[j] = dis[j - 1] + abs(d - x[j]);
    int head = 0, tail = -1;
    que[++tail] = {0, 0};
    for (int j = 1; j <= n; j++) {
      long long int dp = f[tag ^ 1][j] - dis[j];
      while (head <= tail and que[tail].first >= dp) tail--;
      que[++tail] = {dp, j};
      if (j - que[head].second > c) head++;
      f[tag][j] = que[head].first + dis[j];
    }
  }
  cout << (f[tag ^ 1][n] < 0x3f3f3f3f3f3f3f3f ? f[tag ^ 1][n] : -1) << endl;
}
int main() {
  solve();
  return 0;
}
