#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 1e7 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ = 225;
const long double EPS = 1e-7;
ll t[20004];
ll lz[20004];
ll dp[5005][5005];
ll sum[5005];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> x(n + 1);
  for (int i = 1; i < n + 1; i++) cin >> x[i];
  sort(x.begin() + 1, x.end());
  vector<ii> vp(m + 1);
  memset(dp, 63, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i < m + 1; i++) cin >> vp[i].first >> vp[i].second;
  sort(vp.begin() + 1, vp.end());
  deque<int> dq;
  for (int i = 1; i < m + 1; i++) {
    int pos = vp[i].first, cap = vp[i].second;
    dp[i][0] = 0;
    dq.clear();
    sum[0] = 0;
    dq.push_back(0);
    for (int j = 1; j < n + 1; j++) {
      int val = abs(x[j] - pos);
      sum[j] = val + sum[j - 1];
      while (dq.size() &&
             dp[i - 1][j] < dp[i - 1][dq.back()] + sum[j] - sum[dq.back()]) {
        dq.pop_back();
      }
      dq.push_back(j);
      int lo = 0, hi = dq.size() - 1;
      while (lo < hi) {
        int md = lo + (hi - lo) / 2;
        if (dq[md] >= j - cap)
          hi = md;
        else
          lo = md + 1;
      }
      dp[i][j] = dp[i - 1][dq[lo]] + sum[j] - sum[dq[lo]];
    }
  }
  if (dp[m][n] > 1ll * n * 2e9) {
    cout << -1 << '\n';
  } else
    cout << dp[m][n] << '\n';
  return 0;
}
