#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, las;
long long ans;
pair<long long, long long> a[10100], o, tp;
priority_queue<pair<long long, long long> > q;
priority_queue<long long> q2;
int main() {
  cin >> n >> m;
  for (int i = las = n; i--;) cin >> a[i].first, a[i].second = -1;
  for (int i = m; i--;) cin >> a[n].first >> a[n].second, las -= a[n++].second;
  if (las > 0) return 0 * puts("-1");
  sort(a, a + n);
  long long c, t;
  q.push((pair<long long, long long>){-1e12, 1e5});
  for (int i = 0; i < n; ++i) {
    o = a[i];
    if (~o.second) {
      for (; o.second && !q2.empty() && (t = q2.top()) > o.first; --o.second) {
        ans -= c = t - o.first;
        q2.pop();
        q.push((pair<long long, long long>){o.first - c, 1});
      }
      if (o.second) q.push(o);
    } else {
      tp = q.top();
      q.pop();
      c = o.first - tp.first;
      if (--tp.second) q.push(tp);
      ans += c;
      q2.push(o.first + c);
    }
  }
  cout << ans << endl;
}
